首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

哪位高手能给个sql数据库保存图片的例子

2012-03-30 
谁能给个sql数据库保存图片的例子谁能给个sql数据库保存图片的例子,最好是C#语言的,最近做一个窗体,需要动

谁能给个sql数据库保存图片的例子
谁能给个sql数据库保存图片的例子,最好是C#语言的,最近做一个窗体,需要动态输入个人信息,包括图片,但是图片始终无法保存,所以求高人指点或者给个例子,谢谢了

[解决办法]

C# code
  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(); 

热点排行