问题
i would like to know how to save an image into database. I know that we have to convert the image into a byte first and then save it in the database. I have set the data type to byte in the database. I need example projects or code samples on how to go about doing this in visual studios 2010 C#. Thank You
回答1:
if you want find your image
FileInfo fInfo = new FileInfo(yourPath);
long numBytes = fInfo.Length;
FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
byte[] imageData = br.ReadBytes((int)numBytes);
try with these lines based on object type
command.Parameters.Add(new SqlParameter("@Image", (object)imageData));
回答2:
Hey You can save image on a location on your server and save just the name of image in database.
来源:https://stackoverflow.com/questions/12055132/save-image-in-database-visual-studios