下边是源代码 FileStream fs = new FileStream(@"F:\收藏的一些图片\1_coloforlia.jpg", FileMode.Open, FileAccess.Read);
Byte[] btye = new byte[fs.Length];
fs.Read(btye, 0, Convert.ToInt32(fs.Length));
System.IO.MemoryStream imagememorystream = new MemoryStream(btye);
Image i = Image.FromStream(imagememorystream);
this.pictureBox1.Image = i;
this.pictureBox1.Width = i.Width;
this.pictureBox1.Height = i.Height; //把二进制数据保存到数据库
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=meter_data;user id = sa;password=19790601";
try
{
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from temp",conn);
DataSet ds = new DataSet();
sda.Fill(ds);
DataRow myRow;
myRow = ds.Tables[0].NewRow();
myRow[0] = btye;
ds.Tables[0].Rows.Add(myRow);
sda.Update(ds); }
catch (Exception ex)
{ Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
数据库里边就一个字段 是varbinary(MAX)类型的 我加断点执行程序的时候执行通过 但是 没有查询数据库的时候并没有添加内容希望高手帮忙看看是怎么回事
Byte[] btye = new byte[fs.Length];
fs.Read(btye, 0, Convert.ToInt32(fs.Length));
System.IO.MemoryStream imagememorystream = new MemoryStream(btye);
Image i = Image.FromStream(imagememorystream);
this.pictureBox1.Image = i;
this.pictureBox1.Width = i.Width;
this.pictureBox1.Height = i.Height; //把二进制数据保存到数据库
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=meter_data;user id = sa;password=19790601";
try
{
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from temp",conn);
DataSet ds = new DataSet();
sda.Fill(ds);
DataRow myRow;
myRow = ds.Tables[0].NewRow();
myRow[0] = btye;
ds.Tables[0].Rows.Add(myRow);
sda.Update(ds); }
catch (Exception ex)
{ Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
数据库里边就一个字段 是varbinary(MAX)类型的 我加断点执行程序的时候执行通过 但是 没有查询数据库的时候并没有添加内容希望高手帮忙看看是怎么回事
直接insert不行吗?
看上面的代码没有什么问题,sda.Update(ds);
到底执行了什么?是insert,还是update呢?
+1 顶kid insert就行吧
为什么我用insert 的使用 加断点调试的时候 sqlcommmand 的text属性insert into temp (content_binary) values ('System.Byte[]')
呢
为什么我用insert 的使用 加断点调试的时候 sqlcommmand 的text属性C# code insert into temp (content_binary) values ('System.Byte[]') 呢