C# to SQL
-
Can anyone tell me how to store an image from a c# windows form, to a MS SQL Server Database. I've been struggling with this for some time now - please help me if you can. Thanks in advice, Peter
-
Can anyone tell me how to store an image from a c# windows form, to a MS SQL Server Database. I've been struggling with this for some time now - please help me if you can. Thanks in advice, Peter
First, you must convert your image into a bit stream, then save it into a nimage field in your SQL Server. 1. Search about transforming your image into a stream. 2. Search about storing streams into SQL Server. It's not that hard. Free your mind...
-
First, you must convert your image into a bit stream, then save it into a nimage field in your SQL Server. 1. Search about transforming your image into a stream. 2. Search about storing streams into SQL Server. It's not that hard. Free your mind...
I was going along these lines, but part of my problem is that the ways I have seen to do this involve reading the image from a file to put it into a stream, then saving it as an array of bytes. This can then be reversed at the other end. I need to be able to create a byte-array of a System.Drawing.Image.Bitmap variable, to reduce the overhead of saving the file first. As for storing in the SQL server, I did consider using a web-service which re-constructed the stream before saving in the server - not sure if this is possible. There is an 'image' data type in MS SQL, and I was hoping it was going to be as easy as doing an INSERT non-query directly from my c# application, but there seems to be serialization issues here because the System.Drawing.Image.Bitmap data tybe does not implement IConvertable (or something like that). Thanks for your reply - if anyone can help me any further with this problem, I would be MOST grateful. Thanks peter ;P
-
I was going along these lines, but part of my problem is that the ways I have seen to do this involve reading the image from a file to put it into a stream, then saving it as an array of bytes. This can then be reversed at the other end. I need to be able to create a byte-array of a System.Drawing.Image.Bitmap variable, to reduce the overhead of saving the file first. As for storing in the SQL server, I did consider using a web-service which re-constructed the stream before saving in the server - not sure if this is possible. There is an 'image' data type in MS SQL, and I was hoping it was going to be as easy as doing an INSERT non-query directly from my c# application, but there seems to be serialization issues here because the System.Drawing.Image.Bitmap data tybe does not implement IConvertable (or something like that). Thanks for your reply - if anyone can help me any further with this problem, I would be MOST grateful. Thanks peter ;P
Take a look at Bitmap.Save method. You can save it to a memory stream. Then send that memory to the DB. There is a formatter in the System.Web namespace, named LosFormatter (No documentation), that converts any byte array into a string. You can use it to serialize it into a string, then send it thru the webservice. I recomend you to use a Store Procedure to store the Image in the DB instead of a direct INSERT. ;) Free your mind...
-
Can anyone tell me how to store an image from a c# windows form, to a MS SQL Server Database. I've been struggling with this for some time now - please help me if you can. Thanks in advice, Peter
-
C# Photo Album Viewer[^] Mazy No sig. available now.
Thankyou all for your help - Im a good few steps closer to my solution. Thanks again, Peter