可能我没说清楚,我在我在SQL Server 2000中建了一个image类型的字段(photo)用来存储个人照片,做了一个存储过程,然后在类中的方法test加入一句
SqlComm.Parameters .Add ("@Photo",SqlDbType.Image ,16).Value=Photo;
其中SqlCommand SqlComm,@Photo在存储过程中定义为Image ,Byte Photo在winform内加了一个image控件,名为Picture,写入如下代码:
Photo=Convert.ToByte (Picture.Image.GetType () );其中Byte Photo,
但是我将Photo传入到类中的方法test中出错,是类型转换错误,请问该如何定义Photo类型,
编译时是通过的,但执行时就出错,各位帮我一把吧

解决方案 »

  1.   

    a sample:private void readimagefromdb()
    {
    //將數據表中的image讀取到picturebox
    int nowPosition=this.BindingContext[this.dataset1,"customers"].Position ;
    if (!(Convert.IsDBNull(this.dataset1.Tables["customers"].Rows[nowPosition] ["嘜頭"])))
    {
    // Open a stream for the image and write the bytes into it
    byte[] byttrade=(byte[])this.dataset1.Tables["customers"].Rows[nowPosition]["嘜頭"];
    System.IO.MemoryStream stmtrade=new MemoryStream(byttrade);
    stmtrade.Write(byttrade,0,byttrade.Length);
    // Create a bitmap from the stream
    Bitmap bmp=new Bitmap(stmtrade);
    // Check for scaling and assign the bitmap to the Picturebox
    if (bmp.Width >264 && bmp.Height >184)
    {
    Bitmap bmp1=new Bitmap(bmp,new Size(264,184));
    this.pictureBox1.Image=bmp1;
    }
    else
    {this.pictureBox1.Image =bmp;}
    }
    else
    {
    this.pictureBox1.Image=null;
    }
    }
      

  2.   

    方法如下:
    byte[] Data = new Byte[File.ContentLength];
    //force the control to load data in array
    File.InputStream.Read(Data,0,File.ContentLength);
    //Create procedure parameter
    object[] obj = new object[1]; obj[0] = Data;//Execute the procedure with Microsoft.ApplicationBlocks.Data
    //Simple procedure
    /*CREATE PROCEDURE sp_img(@img image)  ASinsert into tb_img values(@img)*///record data
    SqlHelper.ExecuteNonQuery(connectionString,"sp_img",obj);