Stream myStream=new MemoryStream();
this.pictureBox1.Image.Save(myStream,System.Drawing.Imaging.ImageFormat.Jpeg );
myStream.Position = 0;
BinaryReader br = new BinaryReader(myStream);
byte[] imagebyte=br.ReadBytes((int)myStream.Length);
SqlCommand cmd = new SqlCommand("insert into PeopleInfo (CName,CPhoto) VALUES ('"+ this.textBox1.Text +"','"+ imagebyte +"')",conn);
cmd.ExecuteNonQuery(); CPhoto为Image字段,
执行这些语句并没有任何错,但我去看了SQL数据库,写进去CPhoto值为一样,都是0x53797374656D2E427974655B5D(System.byte[]);意思就是每次写进去的数据为System.byte[]
我的天呀,他为什么不写里面的数据,只是写这个TYPE,烦呀,我检查了imagebyte.Length,那有好几K,为什么不写内容而去写那的类型,请高手救命!(写出代码!)
其实就是怎么样把byte[]存到SQL的image字段,但是我一直搞不好!
this.pictureBox1.Image.Save(myStream,System.Drawing.Imaging.ImageFormat.Jpeg );
myStream.Position = 0;
BinaryReader br = new BinaryReader(myStream);
byte[] imagebyte=br.ReadBytes((int)myStream.Length);
SqlCommand cmd = new SqlCommand("insert into PeopleInfo (CName,CPhoto) VALUES ('"+ this.textBox1.Text +"','"+ imagebyte +"')",conn);
cmd.ExecuteNonQuery(); CPhoto为Image字段,
执行这些语句并没有任何错,但我去看了SQL数据库,写进去CPhoto值为一样,都是0x53797374656D2E427974655B5D(System.byte[]);意思就是每次写进去的数据为System.byte[]
我的天呀,他为什么不写里面的数据,只是写这个TYPE,烦呀,我检查了imagebyte.Length,那有好几K,为什么不写内容而去写那的类型,请高手救命!(写出代码!)
其实就是怎么样把byte[]存到SQL的image字段,但是我一直搞不好!
解决方案 »
- 如何设置dropdownlist的onselectedindexchanged事件与js方法关联
- 江湖急救站,第三张贴,大侠有请。(100分)
- 如何获取对象的类型?
- 从哪里可以下载到C#的帮助文档呢?
- 怎么样判断以下情况
- 我参与开发的外国著名开源邮件收发组件OpenPOP.NET和OpenSMTP.NET
- Winform如何给安卓手机安装apk
- 请问:vs2005如何发布windows应用程序
- 关于事件函数button_Click(object sender, System.EventArgs e)的参数
- 从哪儿下载VS。NET正式版的速度比较快???
- 怎样使用正则表达式来规范c#代码格式?
- 关于类型转换出错的问题?
// System.Data.SqlClient.SqlParameter par = new SqlParameter("@image",SqlDbType.Image);
// command = new SqlCommand(strSql,conn);
// par.Value = b;
// command.Parameters.Add(par);
// conn.Open();
// command.ExecuteNonQuery();
// conn.Close();
byte[] b = new byte[reader.Length];
reader.reader(b,0,b.Length);这几句加在最上面就行了
FileStream fs=new FileStream(Image_path,FileMode.Open);
BinaryReader br=new BinaryReader(fs);
imagebytes=br.ReadBytes(br.Length);
SqlParameter parInput22=cmd.Parameters.Add("@员工图片",SqlDbType.Image);
parInput22.Direction=ParameterDirection.Input;
cmd.Parameters["@员工图片"].Value=imagebytes;
cmd.ExecuteNonQuery();