how to save image into sql server ?
-
my code is ..... Dim fs As FileStream = New FileStream(mImageFilePath.ToString(), FileMode.Open) ..... and i can only read image from ' mImageFilePath.ToString()'. Does C# has other way such read/ stream the image from PictureBox control ? so please tell me some guid line if u know ... thank :confused:
-
my code is ..... Dim fs As FileStream = New FileStream(mImageFilePath.ToString(), FileMode.Open) ..... and i can only read image from ' mImageFilePath.ToString()'. Does C# has other way such read/ stream the image from PictureBox control ? so please tell me some guid line if u know ... thank :confused:
SQL Server stores bytes, so you need to save and read the bytes.
// Turning img into bytes
Bitmap bmp = new Bitmap( FILENAME );
MemoryStream ms = new MemoryStream();
bmp.Save( ms, SOMEIMAGEFORMAT );
byte[] imgBytes = ms.ToArray();You can now save imgBytes to SQL using varbinary or image column types. to get it back
// Turning the bytes back into an image
byte[] imgBytes = DirectCast( row["IMAGECOLUMN"], byte());
MemoryStream ms = new MemoryStream( imgBytes );
Bitmap bmp = new Bitmap( ms );Using the wrong tool for the job is half the fun.