谁能给个sql数据库保存图片的例子 谁能给个sql数据库保存图片的例子,最好是C#语言的,最近做一个窗体,需要动态输入个人信息,包括图片,但是图片始终无法保存,所以求高人指点或者给个例子,谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 C#在SQl中存取图片image 存 byte[] imagebytes = null; using (FileStream fs = new FileStream("D:\\12345.jpg", FileMode.Open)) { imagebytes = new byte[fs.Length]; BinaryReader br = new BinaryReader(fs); imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length)); } SqlConnection con = new SqlConnection("Data Source=FCSDL-DT-002\\SQLEXPRESS;Initial Catalog=stuDB;Integrated Security=True"); con.Open(); string sql = "insert into b(ID,zhiwu,picture)values(@ID,@zhiwu,@picture)"; System.Data.SqlClient.SqlParameter[] para = new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@ID",12), new System.Data.SqlClient.SqlParameter("@zhiwu","dahui"), new System.Data.SqlClient.SqlParameter("@picture",imagebytes) }; //string sql = string.Format("insert into b(ID,zhiwu,picture)values({0},'{1}',{2})", 9, "xiaohuilang", imagebytes); SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddRange(para); int resulet = cmd.ExecuteNonQuery(); con.Close();取byte[] imagebytes = null; SqlConnection con = new SqlConnection("Data Source=FCSDL-DT-002\\SQLEXPRESS;Initial Catalog=stuDB;Integrated Security=True"); con.Open(); string sql = "select * from b where ID=11"; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader read = cmd.ExecuteReader(); while (read.Read()) { imagebytes = (byte[])read["picture"]; } read.Close(); con.Close(); MemoryStream ms = new MemoryStream(imagebytes); Bitmap bmpt = new Bitmap(ms); this.pictureBox1.Image = bmpt; 开机用管理员身份启动程序,如何绕过UAC的弹框? 求助:添加现有项后用不了?大家都没试过吗? C#中表示小数用什么类型比较好? 谁有用DGI+画销售曲线图的原码参考一下?? 点击提交按钮没有反应 c# 求助:使用TreeView控件时出现小弟不能解决的问题 Append如何从下一行开始追加? HELP~关于checkedlistbox的问题 关于 System.Windows.Forms.NotifyIcon 的click事件??? 关于 Graphics 类的问题 关于主键,外键的问题 大家看一下这个报表
byte[] imagebytes = null;
using (FileStream fs = new FileStream("D:\\12345.jpg", FileMode.Open))
{
imagebytes = new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
}
SqlConnection con = new SqlConnection("Data Source=FCSDL-DT-002\\SQLEXPRESS;Initial Catalog=stuDB;Integrated Security=True"); con.Open(); string sql = "insert into b(ID,zhiwu,picture)values(@ID,@zhiwu,@picture)";
System.Data.SqlClient.SqlParameter[] para = new System.Data.SqlClient.SqlParameter[] {
new System.Data.SqlClient.SqlParameter("@ID",12),
new System.Data.SqlClient.SqlParameter("@zhiwu","dahui"),
new System.Data.SqlClient.SqlParameter("@picture",imagebytes)
}; //string sql = string.Format("insert into b(ID,zhiwu,picture)values({0},'{1}',{2})", 9, "xiaohuilang", imagebytes); SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddRange(para);
int resulet = cmd.ExecuteNonQuery();
con.Close();取
byte[] imagebytes = null; SqlConnection con = new SqlConnection("Data Source=FCSDL-DT-002\\SQLEXPRESS;Initial Catalog=stuDB;Integrated Security=True"); con.Open(); string sql = "select * from b where ID=11"; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{
imagebytes = (byte[])read["picture"];
}
read.Close();
con.Close(); MemoryStream ms = new MemoryStream(imagebytes);
Bitmap bmpt = new Bitmap(ms);
this.pictureBox1.Image = bmpt;