|
I think given code is for serialization not for deserialization because u used serialize() method instead deserialize() and also create an *.xml file. If I am wrong then plz guide me.
Thnx in adv...
|
|
|
|
|
Hello all
Im comparing two data tables(with same structure)and i want to insert the row difference into the first table
eg
table 1 table 2
ColA ColB ColC ColA ColB ColC
A B C A B C
C D A A A A <---new row
D A C C D A
D A C
as you can see , 2nd row in table 2 is new and I want to insert the difference into table1
|
|
|
|
|
There isn't any automated way to achieve the same.
You need to do it manually.
Just loop datatable for the number of rows for the
datatable has greater rows. i.e.
DataTable1 contains 5 rows
DataTable2 contains 6 rows
then write
for(i=0;i<<DataTable2.Rows.Count;i++)
{
for(j=0;j<<DataTable1.Rows.Count;j++)
{
for(t=0;t<<DataTable1.Columns.Count;t++)
{
}
}
}
Then manually compare each row and each column. You need to take two flags.
First flag set when the column of DataTable1 is not matched with DataTable2
for particular row.
Second flag set when there is new row in DataTable2 not matched with any row
of DataTable1.
And accordingly you can take actions.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
The first thing to try is an INSERT...SELECT...WHERE statement, but that won't work in all cases.
If I have to resort to programming, then depending on the situation (number of rows and columns etc.), I might just throw all the rows in table 2 at table 1 and see what sticks.
0) Ensure that table 1 has a unique index that covers everything that needs to be covered.
1) Set up a parameterized INSERT command for table 1 (this requires a second Connection)
2) Open a DataReader against table 2.
3) Iterate the DataReader
3.1) Set the parameters
3.2) In a try/catch, Execute the INSERT, and ignore (or log) duplicate exceptions
This allows the database to check whether or not the row exists so you don't wind up checking it twice. The big sticking point is the index -- how much data will need to be in the index?
You may also want a Transaction.
Edit: Oh, wait, you meant DataTables? Why would you need to do that?
|
|
|
|
|
Hello,
I am using C# desktop applications.Here I am saving some files into the database and i wanted to read those files back and depending upon my extension it should open in corresponding files.For eg,.doc file in msword,pdf in adobe like that.
I am facing a problem in opening the file .I have binary data in a byte array.How will i do it.Please help
seeism
|
|
|
|
|
Most apps need physical files for their documents, so create a document file (could be in a temp folder), then pass its path to Process.Start() to launch the associated application to open it.
Note: the app may remain open after you're done.
|
|
|
|
|
hey
thanks for that
this is what i actually want.Now i able to open a word document if my file that stored was doc but it is coming as junk value.What could be the reason ???
seeism
|
|
|
|
|
Hi,
I am able to read only the first char of bytes from db.What could be the reason.Now in txt file ,it is opening and prints the first char but for doc,it is coming junk data
seeism
|
|
|
|
|
|
Hi,
I am not getting any error.I just want to open a file in the same application and now my problem is solved using this
String new_FileName = Path.ChangeExtension(Path.GetTempFileName(), "txt");
File.WriteAllBytes(new_FileName, result);
System.Diagnostics.Process.Start(new_FileName);
But now i getting junk values for doc data.
|
|
|
|
|
why would you change the extension? if it is a Word document, NotePad will not be able to open it properly.
The normal thing to do is to use two database fields: one for the filename (including extension!), one for the binary data (the actual file content).
|
|
|
|
|
Soory i pasted the code for txt here.I put it as doc while opening the doc file.For doc file it is coming junk data.For txt first char is printing
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable());
dt.Load(dr);
result = (Byte[])dt.Rows[0]["File_Doc"];
when i check this result array it is contiaing the first byte value and all others r zero
Why so
|
|
|
|
|
use your database management tool to check the content of the field, and determine whether the problem is in storing or in retrieving the data.
BTW: you don't need a DataReader, a simple ExecuteScalar could suffice, see here e.g.: Save An Image Into SQL Server 2000 Database[^]
|
|
|
|
|
I am not much familiar with sql server.How to view the binary data in sql server.
??
|
|
|
|
|
Hey
my probs was solved.oops that was a mistake in the stored proc where i didn mentioned the size of binary data.SO only one data was storing
thanks a lot for ur help.
|
|
|
|
|
Gentleman,
I wrote an application that needs to get the Processor ID from the OS. I have been using it exactly as designed below for the last several years on Win XP and Vista. A recent user of this app reported to me that he is getting an error that would indicate that the Processor Id is not being returned as designed. Now, the only difference that I know of is that he is using Windows 7. Question: is there any reason why the Management Class call that I have here will not work on Win 7?...or should I look for a different problem elsewhere? Thank you in advance...Pat
public string GetProcId()
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuSerial == string.Empty || cpuSerial == null)
{
cpuSerial = mo.Properties["ProcessorId"].Value.ToString();
cpuSerial = cpuSerial.ToUpper().Trim();
}
}
return cpuSerial;
}
|
|
|
|
|
I've never seen code like that; the normal way to interact with Win32_Processor seems to be like this one[^], which works fine for me on XP and Vista.
Probably your Win7 is 64-bit and your code somehow isn't compatible with that, whereas the alternative probably is (can't test right now).
|
|
|
|
|
Thank you for your reply, Luc. As is often the case, there is more than one way to get from here to there. I have been using this exact snippet since at least 2004 and with series 2.0, 3.0, and 3.5 framework...it has always worked in the past and I can find similar examples on the net as well. I have personally tested it on XP, Vista, and 2003 Server and it works fine. This is the first time this has happened, but I until I know why, I have to stop distribution of the program. You have a nice idea re: the Bit version, so I checked it out and this guy is using XP Pro 32 bit, so that lets that idea out. I appreciate your input though, and if you come up with another idea, I'm certainly listening...
Best Regards, Pat
|
|
|
|
|
I have a treeview with ownerdrawn nodes. I also set an invividual indent value for each node, so each node has new bounds. The problem occurs on mouseover, hottracking is not triggered when mousing over the the last portion of the node - portion that equals to the length of the indent. Is there a way to set the mouseover bounds or maybe catch the event that triggers hottracking and force hottracking when mousing over the new bounds?
|
|
|
|
|
I usually read the resource using Properties.Resource.my_resource_name
But I want to pass the name from a variable, something like this:
String var_name = "my_resource_name"
How can I do that?
Thx
|
|
|
|
|
I don't know the full answer, here are some bits and pieces though:
string[] sa=assembly.GetManifestResourceNames();
foreach (string s in sa) log(s);
...
Bitmap bitmap=new Bitmap(type, resourceName);
...
Icon icon=new Icon(type, resourceName);
...
public static void PlaySound(Type type, string resourceName) {
try {
resourceName=type.Namespace+".resources."+resourceName;
Stream stream=type.Assembly.GetManifestResourceStream(resourceName);
int len=(int)stream.Length;
byte[] buf=new byte[len];
stream.Read(buf, 0, len);
GCHandle handle=GCHandle.Alloc(buf);
IntPtr ptr=Marshal.UnsafeAddrOfPinnedArrayElement(buf, 0);
int res=sndPlaySound(ptr, 4);
handle.Free();
env.log(env.TRACE, "Played sound "+resourceName);
} catch (Exception e) {
env.error(resourceName+" failed: "+e.Message);
}
}
|
|
|
|
|
I am first getting a list of strings from files that have dates in them ex. fileabc_20100612_1020.txt in a certain directory(expression S.ImportFolder)
my objective is to get a list of these dates in from a folder. My problem is that there will be some files with same dates in this case I want to select the newest one for that date like closest to 23:59 of that Date.
for example in c:\Temp there is
fileabc_20100612_1020.txt
fileabc_20100613_1020.txt
fileabc_20100614_1020.txt
fileabc_20100614_2320.txt
I would want to only import
fileabc_20100612_1020.txt
fileabc_20100613_1020.txt
fileabc_20100614_2320.txt
or exclude
fileabc_20100614_1020.txt
string[] fileEntries = Directory.GetFiles(S.ImportFolder);
foreach (string fileNameWithRoot in fileEntries)
{
string fileName = System.IO.Path.GetFileName(fileNameWithRoot);
....String manipulation.....
DateTime dtFileName = new DateTime();
try
{
DateTime dtFileName = Convert.ToDateTime(fileName);
}
catch (Exception e)
{
}
dicFiles.Add(dtFileName, fileName);
|
|
|
|
|
I don't see a problem, except for choosing one of many possible ways to get there. Here are some ideas:
1.
your filename convention is such that sorting them alphabetically also sorts them chronologically, that makes things easy. Start by sorting them alphabetically; if you think they already are, that is only true sometimes, it depends on the file system (NTFS versus FAT).
2.
you can convert a datetime string to a DateTime using DateTime.ParseExact() or DateTime.TryParseExact() . Works much better than any Convert method. But you don't have to. See below.
3.
when scanning the files chronologically, you're only interested in the last one of each date, so compare the date (or the first 16 characters, or all but the last 8 characters) of two consecutive names, when equal do nothing, when different, keep the oldest one. Make sure to also keep the very last file.
|
|
|
|
|
I am importing another system's files therefor I do cannot change the file naming convention
so Im thinking of parsing the file into: datetime, full name
How can I compare the each record against each other with the first 8 digits for example 20100719 and if it finds another string node with 20100719 to then look at the substring/node which would be the next 6 digits after the date.
then delete the record that is not the most current for that date.
Thanks in advance
|
|
|
|
|
o0romeo0o wrote: I do cannot change the file naming convention
I never suggested you change it; I said to take advantage of it.
I suggest you reread by earlier reply. it is all in there.
o0romeo0o wrote: How can I compare the each record against each other
There is no need to do that; just sort the array as I said before.
|
|
|
|