|
What Mycroft has stated is correct you shouldn't store dates in the database as strings but I wont go into that as he already has.
If you look at the ExecuteNonQuery[^] documentation you will see that the method returns a value indicating the number of rows effected.
you can then use this value in a string.
string Message = String.Format("Number of rows affected {0}", result);
MessageBox.Show(Message);
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Avoiding SQL Injection[^] isn't hard:
string save = "Insert into ShippingCompany ([ShippingCompanyCode], [ShippingCompanyName], [CurenccyCode], [ActiveStatus], [CreateBy], [CreateDate], [modifiedBy], [modifiedDate]) "
+ "values (@ShippingCompanyCode, @ShippingCompanyName, @CurenccyCode, @ActiveStatus, @CreateBy, @CreateDate, @modifiedBy, @modifiedDate)";
using (SqlConnection con = new SqlConnection(dikonek))
using (SqlCommand cmd = new SqlCommand(save, con))
{
cmd.Parameters.AddWithValue("@ShippingCompanyCode", t1.Text);
cmd.Parameters.AddWithValue("@ShippingCompanyName", t2.Text);
cmd.Parameters.AddWithValue("@CurenccyCode", t3.Text);
cmd.Parameters.AddWithValue("@ActiveStatus", t4.Text);
cmd.Parameters.AddWithValue("@CreateBy", t5.Text);
cmd.Parameters.AddWithValue("@CreateDate", DateTime.Now);
cmd.Parameters.AddWithValue("@modifiedBy", t7.Text);
cmd.Parameters.AddWithValue("@modifiedDate", DateTime.Now);
con.Open();
int rowsAffected = cmd.ExecuteNonQuery();
MessageBox.Show(string.Format("{0} rows affected.", rowsAffected));
}
You should also consider giving your controls more meaningful names than t1 , t2 , etc.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I am trying the following code to create a new XML document but getting the above error.
could you please help..
xml_document = new XDocument();
xml_document.Declaration = new XDeclaration("1.0", "utf-8", "true");
xml_document.Add(new XElement("EventLog"));
XElement event_node = new XElement("Event", new XAttribute("ID", Guid.NewGuid().ToString()));
XElement event_date = new XElement("DateTime", DateTime.UtcNow.ToString("ddd dd MMM yyyy HH:mm:ss"));
XElement event_details = new XElement("Description", event_description);
event_node.Add(event_date);
event_node.Add(event_details);
xml_document.Add(event_node);
xml_document.Save("eventlog.xml");
Technology News @ www.JassimRahma.com
|
|
|
|
|
Shouldn't event_node be added to the root "EventLog " node?
/ravi
|
|
|
|
|
Exactly! OP is trying to add more than one root node to a document which is of course nonsense.
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
How can I fix it?
My xml structure is like this:
<eventlog>
<event id="[GUID]">
<datetime><datetime
>
<description><description>
<event>
<eventlog>
Technology News @ www.JassimRahma.com
|
|
|
|
|
Empty structures are the best!
I guess something went wrong there?
|
|
|
|
|
As Ravi said, you need to add the event_node to the root node, not the document:
xml_document.Root.Add(event_node);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
See my reply here[^].
/ravi
|
|
|
|
|
Try this:
xml_document = new XDocument();
xml_document.Declaration = new XDeclaration("1.0", "utf-8", "true");
XElement rootEle = new XElement("EventLog")
xml_document.Add(rootEle);
XElement event_node = new XElement("Event", new XAttribute("ID", Guid.NewGuid().ToString()));
XElement event_date = new XElement("DateTime", DateTime.UtcNow.ToString("ddd dd MMM yyyy HH:mm:ss"));
XElement event_details = new XElement("Description", event_description);
event_node.Add(event_date);
event_node.Add(event_details);
rootEle.Add(event_node);
xml_document.Save("eventlog.xml");
/ravi
|
|
|
|
|
Thanks Ravi. It solved my problem.
Technology News @ www.JassimRahma.com
|
|
|
|
|
Hi,
I wanna know how can I determine if Google Drive is installed on the machine and what's the drive folder?
How can I do this please?
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
Jassim Rahma wrote: how can I determine if Google Drive is installed Enumerate the installed programs, see if it's there.
Jassim Rahma wrote: and what's the drive folder? Enumerate all drives, and ask for the drive's details (like it's size) using e.g. WMI. It might not spit out that it's a GDrive, but if the app is installed and there's only one drive that does not give a detail like a cluster-size, chances are, that's the GDrive.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
To find out if GDrive is running:
using System.Diagnostics;
private bool IsGDriveRunning()
{
return Process.GetProcessesByName("googledrivesync").Length > 0;
} One way to get the filepath of the running process:
Process[] gDrive = Process.GetProcessesByName("googledrivesync");
if (gDrive.Length > 0)
{
Console.WriteLine(gDrive[0].Modules[0].FileName);
} But, there may be some issues using depending on whether you are compiling to a 32- or 64- bit application. See the discussion here: [^]. Right after that post is an example showing how to use WMI.
On my Win 8/64 system GDrive runs two googledrivesync.exe processes, both resolve to the same file. Your mileage may vary.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Hi,
I have csv file which contains 1 million records and with column 160. I have to insert(update the csv file) more 60 columns in the same file so the total column finally will generated 220.
60 columns and there data will get update like -
for first Row I have to select values from column 2,3,4 and generate the url and execute the url so that I will get xml data. Then I have to parse that data and fill 60 columns for that perticular row.
Like same I have to do for 2 row and 3row....upto 1 million. I have to process this file within 3 hrs.
How I can improve the performance of the reading and writing to csv file.
Regards,
sjs
modified 19-Dec-13 8:59am.
|
|
|
|
|
Sionce we know nothing of your code, it's prretty much impossible to tell you how to improve the performance.
|
|
|
|
|
Here, on CP, Sebastien Lorion's very popular 2011 article, and code, "A Fast CSV Reader," immediately comes to mind: [^]. I think you'll find a good strategy for optimizing access to your file in that article.
But, given: "I have to select values from column 2,3,4 and generate the url and execute the url so that I will get xml data:" does this mean you are writing XML into your CSV file ?
... edit ... you might also examine the open-source file library, FileHelpers: [^]. I have not used this library.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
modified 19-Dec-13 10:16am.
|
|
|
|
|
1 million records isn't so much. The real advantage is you can spawn multiple threads each with a different start point all writing to a different output file then have another app combine the outputs. But if the file was only a few GB I would just load the entire thing into ram in one quick blit and get it over with.
|
|
|
|
|
|
sjs4u wrote: I have to process this file within 3 hrs. Sorry, but that's not how it works. You can't take an arbitrary proces and demand it's being done within a certain time-frame
CSV-files aren't meant to be read or manipulated "fast"; use a database if speed is important.
sjs4u wrote: How I can improve the performance of the reading and writing to csv file. Divide the workload over multiple PC's - then again, we don't know if that's even possible; depends on the structure of the file.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I suspect the problem is not reading/writing the CSV but the manipulation of the records you have to do.
Try breaking the operation into blocks. Read the file, store into a database, process the records and update the database, write out the results. Then identify the slowest operation and work on that.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
sjs4u wrote: 1 million records and ...and execute the url so
That is your bottle neck.
If you need to make 1 million entirely different requests that is going to be a problem. If in fact the requests are duplicates then you can cache the results the first time and then use the cached data after that.
Other than that the url request can be put into a thread, and within reason, you can be waiting on a number of those at one time before proceeding.
|
|
|
|
|
Hi,
have this
public class RecipsMap : ClassMap<Data.Database.Recipe>
{
public RecipsMap()
{
this.Table("Recipe");
this.Id(x => x.Id).GeneratedBy.Native().Column("Id").UnsavedValue(0);
this.Map(x => x.Name).Not.Nullable().Length(50).Unique();
this.Map(x => x.Description).Nullable();
this.Map(x => x.Span);
this.HasMany<Data.Database.Temperature>(x => x.Temperatures).Table("Temperature").Inverse().Cascade.AllDeleteOrphan();
this.HasMany<Data.Database.LampControl>(x => x.LampControls).Table("LampControl").Inverse().Cascade.AllDeleteOrphan();
}
}
with one-to-many relationship.
And in my Repository class i define 2 methods for clear table. Full clear and remove one record by name.
public void Delete()
{
var metadata = this._sessionFactory.GetClassMetadata(typeof(T)) as NHibernate.Persister.Entity.AbstractEntityPersister;
string table = metadata.TableName;
using (var session = this._sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
string deleteAll = string.Format("DELETE FROM \"{0}\"", table);
session.CreateQuery(deleteAll).ExecuteUpdate();
transaction.Commit();
}
}
this.OnOnDataChange(this.Get());
}
public void Delete(string name)
{
using (var session = this._sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
T recipe = session.QueryOver<T>().Where(Restrictions.Eq("Name", name)).SingleOrDefault();
session.Delete(recipe);
transaction.Commit();
}
}
this.OnOnDataChange(this.Get());
}
But,trouble is that data are not deleting cascadely in first case "delete all", but everything is deleting while deleting separate object in second case. If selecting by name as here - all right, if delete all - only recipe table is removing and all other (Temperatures and LampControl tables in relationship) stay at there places. Who dealed with this plz give me advice - how to remove all data from table?
Thanks.
|
|
|
|
|
LIttle_Cat wrote: Who dealed with this plz give me advice - how to remove all data from table? I have not dealt with Hibernate; but then again, if it doesn't support cascading delete's, you can always delete them yourself. Either by executing an extra delete-statement, or by defining a trigger on the database-tables.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for Your attention.
A little bit I understand the proccess but don't know how to solve the problem. I have table with field Id(external key), other two tables references to tjis table. While delete NHibernate kills one child and meets external key which is also must be deleted but can't be deleted because it is one another child. So the question is: how to do it by NHibernate without isage of separate removing? And why this problem does not raising while removing separate strings in parent table, only with cascade removing? The same is going with SQLite database
|
|
|
|