10-31-2011، 03:05 PM
فکر نکنم نیاز به توضیح داشته باشه .
کد:
try
{
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] arrImage = ms.GetBuffer();
ms.Close();
SqlConnection con = new SqlConnection("server=(local);trusted_connection=yes;database=DbName;");
string strSQL = "INSERT INTO TabeName (filename,pic,id) VALUES ( @filename, @pic,@id)";
SqlCommand cmd = new SqlCommand(strSQL, con);
cmd.Parameters.Add(new SqlParameter("@filename", SqlDbType.Char, 50)).Value = textBox2.Text;//filename
cmd.Parameters.Add(new SqlParameter("@pic", SqlDbType.Binary)).Value = arrImage;//picture
cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.Char, 50)).Value = textBox3.Text;//id
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Insert completed seccessfully.");;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}