//图像数据表:tx
//字段id (nvarchar(50) ,image(image)
//tgav为图片ID,实质为上传前的主名 (省略了.jpg)
private void kkkkk(byte[] imgBytesIn,string tgav)
{
try
{
SqlConnection con = new SqlConnection("server=MY\\SQLEXPRESS;uid=sa;pwd=*******;database=exaaam");
con.Open();
SqlCommand cmd = new SqlCommand("insert into tx (id,image) values( @id,@Image ) ;", con);
cmd.Parameters.Add("@id", SqlDbType.NChar);
cmd.Parameters["@id"].Value = tgav;
cmd.Parameters.Add("@Image", SqlDbType.Image);
cmd.Parameters["@Image"].Value = imgBytesIn;
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('图片上传成功!')</script>");
//MessageBox.Show("图片上传成功");
}
catch
{
Response.Write("<script>alert('您选择的图片不能被读取或文件类型不对!')</script>");
}
函数调用:
url = "d:\\tx\\" + txa + ".jpg";
if (File.Exists(url))
{
dd = GetPictureData(url);
kkkkk(dd, txa);
}