110,537
社区成员
发帖
与我相关
我的任务
分享
OpenFileDialog opendialog = new OpenFileDialog(); //打开 文件对话框
opendialog.Filter = "JpegAndGif|*.jpg;*.Gif;*.png"; //筛选格式
opendialog.RestoreDirectory = true;
opendialog.FilterIndex = 1;
if (opendialog.ShowDialog() == DialogResult.OK)
{
pictureaddress = opendialog.FileName; // 获取地址
pictureBox1.Image = Image.FromFile(pictureaddress, false); // 用picturebox1显示图片
}
class db
{
public static void ExecSql(string strsql, string image)
{
FileStream fs = File.OpenRead(image);
byte[] imageb = new byte[fs.Length];
fs.Read(imageb, 0, imageb.Length);
fs.Close();
SqlConnection con = Getconn();
SqlCommand cmd = new SqlCommand(strsql, con);
cmd.Parameters.Add("@Content", SqlDbType.Image);
cmd.Parameters["@Content"].Value = imageb;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}