RT

解决方案 »

  1.   

    读取图片了
    private void button_showimg_Click(object sender, EventArgs e)
    {
    string sqlText = "server=localhost;initial catalog=Test; integrated security=true";
    string sqlstr = "select *from tast where whf=1";
    SqlConnection conn = new SqlConnection(sqlText);
    conn.Open();
    SqlCommand comm = new SqlCommand(sqlstr, conn);
    SqlDataAdapter da=new SqlDataAdapter ();
    da.SelectCommand=comm;
    DataSet ds=new DataSet ();
    da.Fill(ds);
    MemoryStream ms = new MemoryStream((byte[])ds.Tables[0].Rows[0][1]);
    Image i = Image.fromStream(ms,true);
    pictureBox1.Image = i;

      

  2.   

    下面是插入图像到数据库,代码如下:
      private void button_connect_Click(object sender, EventArgs e)
    {
    string sqlText = "server=localhost;initial catalog=Test; integrated security=true";
    string sqlstr = "insert into tast(photo) values(@image) ";
    SqlConnection conn = new SqlConnection(sqlText);
    conn.Open();
    SqlCommand comm = new SqlCommand(sqlstr, conn);
    comm.Parameters.Add("@image", SqlDbType.Image).Value = GetPhoto("DSC_6126.JPG");
    comm.ExecuteNonQuery();
    conn.Close();
    }
    public byte[] GetPhoto(string str1)
    {
    string str = str1;
    FileStream file = new FileStream(str, FileMode.Open, FileAccess.Read);
    byte[]photo=new byte[file.Length];
    file.Read(photo,0,photo.Length);
    file.Close();
    return photo;

      

  3.   

    http://hi.csdn.net/invite.php?u=3370434&c=9cb528505d2f42a0 加好友谢谢!