我想知道如何在桌面上浏览图片并将图片上传到我的表单,然后将其保存到我的数据库中。这是我的朋友所做的,但它对我不起作用。我不知道为什么请帮忙。
MemoryStream ms = new MemoryStream();
pictureBox11.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
SqlConnection con = new SqlConnection("Data Source=LAPTOP;Initial Catalog=db;Integrated Security=True");
SqlCommand cmd = new SqlCommand(query, con);
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"INSERT INTO tblperson([product name],[pics],[user]) VALUES(@value1,@value2,@value3)";
cmd.Parameters.AddWithValue("@value1", txtproductname.Text);
cmd.Parameters.AddWithValue("@value2", picbase64);
cmd.Parameters.AddWithValue("@value3", lbluser.Text);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Picture Saved");
con.Close();
txtproductname.Text = "";
pictureBox11.Image = LessonMidterm1.Properties.Resources.Person;