mshauny 25 Junior Poster in Training

Hi

Any suggestion on how to save an image file into mysql using the .NET api?

I tried code similar to this :

MemoryStream stream = new MemoryStream();
byte[] imgData;
//previously available image in the program
Image.Save(stream,ImageFormat.Jpeg);// saves the image into the stream
imgData = stream.ToArray(); //now I have the bytes in my array

StringBuilder sb = new StringBuilder();

foreach(byte n in imgData)
sb.Append(n);

//assuming the connection is open and everything is init
MysqlCommand cmd = new MysqlCommand("INSERT INTO myTable(binarydata) VALUES('"+sb.ToString()+"')");
int affetced = cmd.ExecuteNoQuery();

Don't pay attention to sytax that much I just wanna know how would somebody do it as I can flush the values to the table but the saved bytes can't construct the image or file again.

I'm so confused and under a lot of pressure to get this done, I might be missing something

Thanks for your input