1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
private void button1_Click(object sender, EventArgs e)
{
if (pictureBox1.Image != null)
pictureBox1.Image.Dispose();
SqlCommand cmds = new SqlCommand();
cmds.CommandText = "sp_select_pic_data";
cmds.CommandType = CommandType.StoredProcedure;
cmds.Connection = con;
SqlParameter p = new SqlParameter();
p.Value = int.Parse(num.Text);
p.Direction = ParameterDirection.Input;
p.SqlDbType = SqlDbType.BigInt;
p.ParameterName = "npic";
SqlParameter p2 = new SqlParameter();
p2.Value = int.Parse(pic.Text);
p2.Direction = ParameterDirection.Input;
p2.SqlDbType = SqlDbType.BigInt;
p2.ParameterName = "c000";
cmds.Parameters.Add(p);
cmds.Parameters.Add(p2);
MemoryStream ms=null;SqlDataReader d=null;
try
{
con.Open();
d= cmds.ExecuteReader();
if (d.Read())
ms = new MemoryStream((Byte[])d[0]);
d.Close();
}
catch (Exception r)
{
MessageBox.Show(r.Message);
}
finally
{
d.Dispose();
d = null;
con.Close();
cmds.Dispose();
cmds = null;
}
try
{
Image im = Bitmap.FromStream(ms);
if (File.Exists(Application.StartupPath + "\\nom.jpg"))
File.Delete(Application.StartupPath + "\\nom.jpg");
im.Save(Application.StartupPath + "\\nom.jpg", ImageFormat.Jpeg);
ms.Close();
ms.Dispose();
ms = null;
}
catch (Exception m)
{
MessageBox.Show(m.Message);
}
} |
Partager