1,数据库使用字段image类型,
2,然后读出图片到byte[] bs,
3,创建参数@pic = bs,
3,更新数据库update tpic set Pic = @pic;

解决方案 »

  1.   

    参考如下:将 BLOB 值写入数据库  [C#]可以将二进制大对象 (BLOB) 作为二进制或字符数据写入数据库,具体视数据源的字段类型而定。若要将 BLOB 值写入数据库,请发出相应的 INSERT 或 UPDATE 语句并将 BLOB 值作为输入参数传递(请参见将存储过程用于命令)。如果 BLOB 存储为文本格式(如 SQL Server text 字段),则可将 BLOB 作为字符串参数传递。如果 BLOB 存储为二进制格式(如 SQL Server image 字段),则可将类型 byte 的数组作为二进制参数传递。
    注意   BLOB 可能会相当大,因此作为单个值写入时可能会占用大量的系统内存,从而导致应用程序性能下降。若要减少写入 BLOB 值时所使用的内存量,可以按“块”将 BLOB 写入数据库。用该方法将 BLOB 写入数据库的过程具体取决于数据源的功能。有关按“块”将 BLOB 值写入 SQL Server 的示例,请参见将 BLOB 值写入 SQL Server 时保留资源。
    以下代码示例将员工信息添加到 Northwind 数据库中的 Employees 列表中。员工照片将从文件中读取并添加到表中的 Photo 字段,该字段为 image 字段。
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;public class EmployeeData
    {
      public static void Main()
      {
        DateTime hireDate = DateTime.Parse("5/21/99");
        AddEmployee("Jones", "Mary", "Sales Representative", hireDate, 5, "jones.bmp");
      }  public static void AddEmployee(string lastName, string firstName, string title, DateTime hireDate , int reportsTo, string photoFilePath)
      {
        byte[] photo = GetPhoto(photoFilePath);    SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");    SqlCommand addEmp = new SqlCommand("INSERT INTO Employees (LastName, FirstName, Title, HireDate, ReportsTo, Photo) " +
                                           "Values(@LastName, @FirstName, @Title, @HireDate, @ReportsTo, @Photo)", nwindConn);     addEmp.Parameters.Add("@LastName",  SqlDbType.NVarChar, 20).Value = lastName;
        addEmp.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10).Value = firstName;
        addEmp.Parameters.Add("@Title",     SqlDbType.NVarChar, 30).Value = title;
        addEmp.Parameters.Add("@HireDate",  SqlDbType.DateTime).Value     = hireDate;
        addEmp.Parameters.Add("@ReportsTo", SqlDbType.Int).Value          = reportsTo;    addEmp.Parameters.Add("@Photo",     SqlDbType.Image, photo.Length).Value = photo;    nwindConn.Open();    addEmp.ExecuteNonQuery();    nwindConn.Close();
      }  public static byte[] GetPhoto(string filePath)
      {
        FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fs);    byte[] photo = br.ReadBytes((int)fs.Length);    br.Close();
        fs.Close();    return photo;
      }
    }
      

  2.   

    保存images进SQL Server数据库
    Stream imgdatastream = File1.PostedFile.InputStream;int imgdatalen = File1.PostedFile.ContentLength;string imgtype = File1.PostedFile.ContentType;string imgtitle = TextBox1.Text;byte[] imgdata = new byte[imgdatalen];int n = imgdatastream.Read(imgdata,0,imgdatalen);string connstr=((NameValueCollection)Context.GetConfig("appSettings"))["connstr"];SqlConnection connection = new SqlConnection(connstr);SqlCommand command = new SqlCommand("INSERT INTO ImageStore(imgtitle,imgtype,imgdata)VALUES ( @imgtitle, @imgtype,@imgdata )", connection ); SqlParameter paramTitle = new SqlParameter("@imgtitle", SqlDbType.VarChar,50 );paramTitle.Value = imgtitle;command.Parameters.Add( paramTitle); SqlParameter paramData = new SqlParameter( "@imgdata", SqlDbType.Image );paramData.Value = imgdata;command.Parameters.Add( paramData ); SqlParameter paramType = new SqlParameter( "@imgtype", SqlDbType.VarChar,50 );paramType.Value = imgtype;command.Parameters.Add( paramType ); connection.Open();int numRowsAffected = command.ExecuteNonQuery();connection.Close();
      

  3.   

    从数据库中输出图片
    private void Page_Load(object sender, System.EventArgs e){string imgid =Request.QueryString["imgid"];string connstr=((NameValueCollection)Context.GetConfig("appSettings"))["connstr"];string sql="SELECT imgdata, imgtype FROM ImageStore WHERE id = "+ imgid;SqlConnection connection = new SqlConnection(connstr);SqlCommand command = new SqlCommand(sql, connection);connection.Open();SqlDataReader dr = command.ExecuteReader();if(dr.Read()){        Response.ContentType = dr["imgtype"].ToString();        Response.BinaryWrite( (byte[]) dr["imgdata"] );}connection.Close();}
      

  4.   

    ~按hawk234(鹰) 的说法做就可以了