如何利用csharp语句向数据库中添加图片 (c 客户端传图片到数据库)
数据库中存图片地址,图片存在服务器磁盘上啊
FileStream fs = new FileStream(@”E:\c.jpg”, FileMode.Open,FileAccess.Read);
Byte btye2 = new byte;
fs.Read(btye2 , 0, Convert.ToInt32(fs.Length));
fs.Close();
using (SqlConnection conn = new SqlConnection(sqlconnstr))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = “insert into T_Img(imgfile) values(@imgfile)”;
SqlParameter par = new SqlParameter(“@imgfile”, SqlDbType.Image);
par.Value = btye2 ;
cmd.Parameters.Add(par);
int t=(int)(cmd.ExecuteNonQuery());
if (t > 0)
{
Console.WriteLine(“插入成功”);
}
conn.Close();
}