将图像上传到SQL数据库

将图像上传到SQL数据库,第1张

图像传到SQL数据库

尝试将图像转换为

Byte[]
数组,然后保存。

 private void btnAdd_Click(object sender, EventArgs e) {    Students myStudent = new Students();    ...    ...    // change the student photo to byte array e.g.     // public byte[] Photo {get;set;}    myStudent.photo = imageToByteArray(Image.FromFile(openFileDialog1.FileName));    ...    ...    // Insert New Record    if (myStudent.AddStudent(myStudent))    MessageBox.Show("Student Added Successfully"); } // convert image to byte array public byte[] imageToByteArray(System.Drawing.Image imageIn) {    MemoryStream ms = new MemoryStream();    imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);    return  ms.ToArray(); }//Byte array to photopublic Image byteArrayToImage(byte[] byteArrayIn){     MemoryStream ms = new MemoryStream(byteArrayIn);     Image returnImage = Image.FromStream(ms);     return returnImage;}

注意:您数据库中的数据

image
类型必须为type



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5640366.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存