954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Mysql .NET API

Hi

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

I tried code similar to this :
[code]
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();
[code]

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

mshauny
Junior Poster in Training
62 posts since Jan 2010
Reputation Points: 35
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: