日期:2014-05-18 浏览次数:20779 次
private void button4_Click(object sender, EventArgs e) //存图片
{
MemoryStream stream = new MemoryStream();
byte[] photo = null;
Image img = this.pictureBox1.Image;
img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
photo = stream.ToArray();
stream.Close();
string sql = "Insert into staff (ID,Photo) Values ('001',@img)";
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\d.mdb");
conn.Open();
OleDbCommand comm = new OleDbCommand(sql, conn);
comm.Parameters.Add("@img", OleDbType.VarBinary, photo.Length).Value = photo;
comm.ExecuteNonQuery();
conn.Close();
}
private void button5_Click(object sender, EventArgs e) //取图片
{
string sql = "Select photo From staff Where ID='001'";
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\d.mdb");
conn.Open();
OleDbCommand comm = new OleDbCommand(sql, conn);
OleDbDataReader sdr = comm.ExecuteReader();
sdr.Read();
MemoryStream ms = new MemoryStream((byte[])sdr[0]);
Image image = Image.FromStream(ms);
sdr.Close();
conn.Close();
pictureBox1.Image = image;
}