Storing and retrieving objects inside databse
-
Hi i want to store and retrieve objects of any kind to SQL server database, i did the following, inside the database table, i had created a field of type varbinary(MAX), and in the code, i had made the following to store the object
object treatment = dataGridViewDrugList.Rows;
MemoryStream memStream = new MemoryStream();
StreamWriter sw = new StreamWriter(memStream);
sw.Write(treatment);
dataRow[0] = memStream.GetBuffer();and it was successful, now i am not able to retrieve the object back any ideas?
-
Hi i want to store and retrieve objects of any kind to SQL server database, i did the following, inside the database table, i had created a field of type varbinary(MAX), and in the code, i had made the following to store the object
object treatment = dataGridViewDrugList.Rows;
MemoryStream memStream = new MemoryStream();
StreamWriter sw = new StreamWriter(memStream);
sw.Write(treatment);
dataRow[0] = memStream.GetBuffer();and it was successful, now i am not able to retrieve the object back any ideas?
Try to 'serialize' the object, as opposed to simply trying to wildly dump it's contents. There's an example using the XmlSerializer on MSDN; once it works, you replace the XmlSerializer with a BinaryFormatter and you're done.
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
Try to 'serialize' the object, as opposed to simply trying to wildly dump it's contents. There's an example using the XmlSerializer on MSDN; once it works, you replace the XmlSerializer with a BinaryFormatter and you're done.
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
Here[^] it is. Serialization may take some getting-used-to, but it's more versatile than dumping memory. I'd recommend building it in two separate steps; First, create a small console-app to serialize a random object. Once that works, you should be able to switch between Xml-serialization and binary with ease. Second part would be to store that "information" in a database. That will work the same way for any information; if you get stuck once you're there, simply come back and we'll look at it again :)
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
Here[^] it is. Serialization may take some getting-used-to, but it's more versatile than dumping memory. I'd recommend building it in two separate steps; First, create a small console-app to serialize a random object. Once that works, you should be able to switch between Xml-serialization and binary with ease. Second part would be to store that "information" in a database. That will work the same way for any information; if you get stuck once you're there, simply come back and we'll look at it again :)
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
Thanks, i solved the issue, my error was that i was trying to serialize an object of type DataGridViewRowCollection which is not marked as a Serializable object, i made my custom class which marked as Serializable, i had stored all the data in the DataGridViewRowCollection in that class, now everything is OK thanks again,