(转载)如何将图片存进数据库
openFileDialog1.Filter = "*jpg|*.JPG|*.GIF|*.GIF|*.BMP|*.BMP";
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
try
{
string fullpath =openFileDialog1.FileName;//文件路径
FileStream fs = new FileStream(fullpath, FileMode.Open);
byte[] imagebytes =new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
//打开数所
SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=;database=zh");
con.Open();
SqlCommand com = new SqlCommand("insert into Image values(@pubimga)",con);
SqlParameter para =com.Parameters .Add("@pubimga",SqlDbType.Image,16);
para.Value =imagebytes;
com.ExecuteNonQuery();
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message );
}
}

浙公网安备 33010602011771号