如何将图片框当前图像保存到数据库 [英] How do I save picturebox current image to database

查看:102
本文介绍了如何将图片框当前图像保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里初学者

所以我使用下面这段代码来查看table1 / database中的照片。通过在文本框中键入RefNo,图像将从table1 / database调用并显示在picturebox1中,我想将其保存到table2 / database。



我尝试过:



 sqlCon.Open(); 

string sqlSelectQuery = SELECT * FROM MNDBagShellTb WHERE BsRefNo = @BsRefNo;
使用(SqlCommand cmd = new SqlCommand(sqlSelectQuery,sqlCon))
{
cmd.Parameters.AddWithValue( @ BsRefNo,(txtRef.Text));

使用(SqlDataReader dr = cmd.ExecuteReader())
{
if (dr.Read())
{
// stockDetails
imageBytes = dr [ SbsImage] as byte [];
if (imageBytes!= null
{
使用 var stream = new MemoryStream(imageBytes) )
pbxBagImg.Image = Image.FromStream(stream);
}
}
}
}
sqlCon.Close();

解决方案

所以,拿你的imageBytes并将其保存到table2。



提示:可能代码首先保存到table1并且你可以用于table2。



或者只是使用存储过程来使用适当的SQL INSERT或UPDATE(table1到table2)参数

Hi beginner here
So I'm using this code below to view the photo from table1/database. By typing the RefNo in the textbox the image will be called from table1/database and display in picturebox1 and I want to to save it to table2/database.

What I have tried:

sqlCon.Open();

string sqlSelectQuery = "SELECT * FROM MNDBagShellTb WHERE BsRefNo = @BsRefNo";
using (SqlCommand cmd = new SqlCommand(sqlSelectQuery, sqlCon))
{
   cmd.Parameters.AddWithValue("@BsRefNo", (txtRef.Text));

   using (SqlDataReader dr = cmd.ExecuteReader())
   {
      if (dr.Read())
      {
         //stockDetails
         imageBytes = dr["SbsImage"] as byte[];
         if (imageBytes != null)
         {
            using (var stream = new MemoryStream(imageBytes))
            pbxBagImg.Image = Image.FromStream(stream);
         }
      }
   }
}
   sqlCon.Close();

解决方案

So, take your "imageBytes" and save it to "table2".

Hint: there's probably code around that first saved to "table1" and you can use for "table2".

Or just use a "stored procedure" to do an SQL INSERT or UPDATE ("table1" to "table2") using the appropriate parameters.


这篇关于如何将图片框当前图像保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆