void Button1Click(object sender, System.EventArgs e)
{
OdbcConnection cn;
OdbcCommand cmd;
OdbcDataReader rs=null;
string MyString;
MyString="Select * from gen_studentinfo";
cn= new OdbcConnection("DSN=mysql1;");
cn.Open();
cmd=new OdbcCommand(MyString,cn);
try
{
rs=cmd.ExecuteReader();
if(rs.Read())
{
byte[]tmp;
Bitmap MyImage;
tmp=(byte[])rs["si_photo"];
if(File.Exists("tmp.tmp")) //文件是否存在
{
File.Delete("tmp.tmp");
}
FileStream fs = new FileStream("tmp.tmp",FileMode.CreateNew);
BinaryWriter w = new BinaryWriter(fs);
w.Write(tmp);
w.Close();
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage ;
MyImage = new Bitmap("tmp.tmp");
pictureBox1.ClientSize = new Size(pictureBox1.Width,pictureBox1.Height);
pictureBox1.Image=(Image)MyImage ;
System.Windows.Forms.MessageBox.Show(rs["si_name"].ToString());
}
}
catch
{ }
finally
{
cn.Close();
cn.Dispose();
}
System.Windows.Forms.MessageBox.Show("Connected");
}