日期:2014-05-18 浏览次数:20880 次
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();