private void button1_Click(object sender, EventArgs e)
        {            byte[] imagesbytes = null;//where CardID='"+ textBox1.Text.Trim() +"' 
            //string txt = null;
            SqlConnection con = new SqlConnection("server=(local);Integrated Security=SSPI;database=library");
            con.Open();
            SqlCommand com = new SqlCommand("Select Picture from Pic ", con);
            SqlDataReader sdr = com.ExecuteReader();
            while (sdr.Read())
            {
                //if (sdr.GetValue(0) == null)
                //    MessageBox.Show(sdr[0].ToString());
                //else
                    imagesbytes = (byte[])sdr.GetValue(0);
                //MessageBox.Show(sdr.GetValue(0).ToString());
            }
            sdr.Close();
            MemoryStream ms = new MemoryStream(imagesbytes);
            Bitmap bmpt = new Bitmap(ms);//错误出现地
            pictureBox1.Image = bmpt;        }        private void button2_Click(object sender, EventArgs e)//把要传的图片上传到数据库
        {
             //System.IO.FileStream fs2;
            openFileDialog1.Filter = "(*.jpg)|*.jpg|(*.bmp)|*.bmp|(*.gif)|*.gif";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                
                pictureBox1.ImageLocation =openFileDialog1.FileName;
                FileStream fs2 = File.OpenRead(pictureBox1.ImageLocation);
                // FileStream fs2 = new FileStream(pictureBox1.ImageLocation, FileMode.Open, FileAccess.Read);
                byte[] imagebytes = new byte[fs2.Length];//fs.lenth文件流长度,用字节表示
                BinaryReader br = new BinaryReader(fs2);//二进制读写器
                imagebytes = br.ReadBytes(Convert.ToInt32(fs2.Length));
                // fs.Read(imagebytes, 0, imagebytes.Length );                SqlConnection con = new SqlConnection("server=(local);Integrated Security=SSPI;database=library");
                con.Open();
                SqlCommand cmd = new SqlCommand("INSERT INTO Pic(Picture)VALUES('imagebytes')", con);
                cmd.ExecuteNonQuery();                MessageBox.Show("添加成功");
                con.Close();
            }
        }