当blob字段插进去就行了。
用BinaryReader,Stream
就可以了。

解决方案 »

  1.   

    转:
    -------
    把图片读到pictureBox,再写入数据库SqlConnection conn=new SqlConnection(@"data source=chenyuming2004\VSdotNET;uid=sa;pwd=cym;database=lhf");
    conn.Open();
    SqlCommand cmd=new SqlCommand("insert into fuser values ('1a','1b',@i)",conn);
    byte[] ib=new Byte[60000];
    FileStream fs=new FileStream(@"D:\windows temp\temp\1.jpg",FileMode.Open ,FileAccess.Read );
    fs.Read(ib,0,60000);
    cmd.Parameters.Add("@i",SqlDbType.Image,(int)fs.Length);
    cmd.Parameters["@i"].Value=ib;
    cmd.ExecuteNonQuery();
    conn.Close();-------------------------------------------------------
    从数据库读图片到pictureboxSqlConnection conn=new SqlConnection(@"data source=chenyuming2004\VSdotNET;uid=sa;pwd=cym;database=lhf");
    conn.Open();
    SqlCommand cmd=new SqlCommand("select 照片 from fuser where password='1b'",conn);
    SqlDataReader reader=cmd.ExecuteReader();
    reader.Read();
    MemoryStream buf=new MemoryStream((byte[])reader[0]);
    Image image=Image.FromStream(buf,true);
    pictureBox1.Image=image;
      

  2.   

    //插入
    DataRowCollection rc; 
    DataRow myNewRow;
    // Create an array with three elements.
    object[] rowVals = new object[11];
    rc = DS.Tables[0].Rows;
    rowVals[0] = EmployeeID.Text;
    rowVals[1] = FirstName.Text;
    rowVals[2] = LastName.Text;
    rowVals[3] = Title.Text;
    rowVals[4] = Extension.Text;
    rowVals[5] = Mobilephone.Text;
    rowVals[6] = officelocation.Text;
    rowVals[7] = System.DateTime.Parse(Birthday.Text);
    rowVals[8] = sittinglocation.Text;
    rowVals[10] = comboBox1.SelectedValue;if (openFileDialog1.FileName!=null && openFileDialog1.FileName!="")
    {
    FileStream st = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
    BinaryReader mbr = new BinaryReader(st);
    Byte[] buffer= new byte[st.Length];
    mbr.Read(buffer, 0, (int)(st.Length));
    st.Close();
    rowVals[9] = buffer;
    }
    else
    {
    rowVals[9] = DBNull.Value;//OleDbType.Empty;
    }
    // Add and return the new row.
    try
    {
    myNewRow = rc.Add(rowVals); oleDbDataAdapter1.Update(DS.Tables[0]);
    DS.AcceptChanges();
    CurrentRow=DS.Tables[0].Rows.Count-1;
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString());
    }
    //图像选择
    private void picture_DoubleClick(object sender, System.EventArgs e)
    {
    openFileDialog1.InitialDirectory = @"C:\";
    openFileDialog1.DefaultExt = "jpg";
    openFileDialog1.Filter = "Bmp Files(*.bmp)|*.bmp|Gif Files(*.gif)|*.gif|Jpg Files(*.jpg)|*.jpg";
    openFileDialog1.ShowDialog();
    picture.Image = Image.FromFile(openFileDialog1.FileName);
    }//显示图像
    private void Display_Record(int CurrentRow)
    {
    DS.Tables[0].Clear();
    oleDbDataAdapter1.Fill(DS,"employee");
    DataView dv_employee = new DataView(DS.Tables[0],"employeeid='"+DS.Tables[0].Rows[CurrentRow][0].ToString()+"'","",DataViewRowState.CurrentRows);
    try
    {
    if (CurrentRow>=0 && CurrentRow<=DS.Tables[0].Rows.Count -1)
    {
    EmployeeID.Text=dv_employee.Table.Rows[CurrentRow][0].ToString();
    FirstName.Text=dv_employee.Table.Rows[CurrentRow][1].ToString();
    LastName.Text=dv_employee.Table.Rows[CurrentRow][2].ToString();
    Title.Text=dv_employee.Table.Rows[CurrentRow][3].ToString();
    Extension.Text=dv_employee.Table.Rows[CurrentRow][4].ToString();
    Mobilephone.Text=dv_employee.Table.Rows[CurrentRow][5].ToString();
    officelocation.Text=dv_employee.Table.Rows[CurrentRow][6].ToString();
    Birthday.Text=Convert.ToString(dv_employee.Table.Rows[CurrentRow][7].ToString());
    sittinglocation.Text=dv_employee.Table.Rows[CurrentRow][8].ToString(); if (dv_employee.Table.Rows[CurrentRow][9] != null && dv_employee.Table.Rows[CurrentRow][9] != DBNull.Value)
    {
    byte[] p_stream = (byte[])dv_employee.Table.Rows[CurrentRow][9];
    Stream st = new MemoryStream(p_stream);
    picture.Image=Image.FromStream(st);
    st.Close();
    }
    else
    {
    picture.Image=null;
    }
    picture.Refresh(); comboBox1.SelectedValue=dv_employee.Table.Rows[CurrentRow][10].ToString();

    RecordNumber.Text="CurrentRow is " + Convert.ToString(CurrentRow+1) + ", Total is "+DS.Tables[0].Rows.Count.ToString();
    }
    else
    {
    RecordNumber.Text="No Record!";
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString());
    }
    }
      

  3.   


        xiangding(谁知盘中餐,离离皆辛苦(同志们啊,要珍惜现在的幸福) 
       BearRui(我有点笨,但我很特别,所以我特别笨!)   wangsaokui(无间道III(终极无间)) ( 
    楼上三位再加我都要给分  楼主知道吗?