如何将图片存入access数据库,C#实现!
如何读取!?谢谢

解决方案 »

  1.   

    System.IO.Stream imgdatastream=this.myFile.PostedFile.InputStream;
    int imgDataLen=this.myFile.PostedFile.ContentLength;
    string imgType=this.myFile.PostedFile.ContentType;
    string imgName=this.myFile.PostedFile.FileName;

    int iPos=imgName.LastIndexOf(@"\");
    imgName=imgName.Substring(iPos+1,imgName.Length-iPos-1);

    byte[] imgData=new byte[imgDataLen];imgdatastream.Read(imgData,0,imgDataLen);下面是一段VB的代码,参考一下就行了        Dim command As SqlCommand = New SqlCommand("INSERT INTO ImageStore(imgtype,imgdata) values(@imgtype,@imgdata )", connection)        //插入参数
            Dim paramData As SqlParameter = New SqlParameter("@imgdata", SqlDbType.Image)
            paramData.Value = imgData
            command.Parameters.Add(paramData)
      

  2.   

    FileStream ImageFile = new FileStream( "图片",FileMode.Open );
    byte bytes = new byte[(int)ImageFile .Length];
    ImageFile .Read( bytes,0,bytes.Length);
    if (intFile>0)
    {
    conn = new OleDbConnection( this.strSqlConn );
    this.strSqlCmd = "Insert into table (Img) values (@Image)" ;
    cmd = new OleDbCommand( strSqlCmd,conn );
    conn.Open();
    cmd.Parameters.Add("@Image",OleDbType.Binary);cmd.Parameters["@Image"].Value = bytes cmd.ExecuteNonQuery();
    }
      

  3.   

    请问在access中,关于图片的字段的类型应该设成什么?
      

  4.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=2A5DD7C6-A45A-48AB-A2E8-342A29F17506