Save image in database visual studios

血红的双手。 提交于 2019-12-12 22:35:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!