http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=6404

解决方案 »

  1.   

    http://www.jzeb.net/bbs/dispbbs.asp?boardID=1&ID=18
      

  2.   

    if(txtFile.PostedFile!=null & txtFile.PostedFile.ContentLength!=0)
    {
    SqlConnection con=Connection.Con();
    string strFname=System.IO.Path.GetFileName(txtFile.PostedFile.FileName);string strFtype=txtFile.PostedFile.ContentType;
    int intFsize=txtFile.PostedFile.ContentLength;System.IO.Stream fileStream=txtFile.PostedFile.InputStream;

    Byte[] b=new Byte[fileStream.Length];
    fileStream.Read(b,0,b.Length);
    fileStream.Close();con.Open();SqlCommand  cmd=new SqlCommand(@"Insert into [file](name,content,ftype,fsize) values( @Name,@Content,@ftype,@fsize)",con);

    SqlParameter pFileName=new SqlParameter("@Name",SqlDbType.NVarChar,strFname.Length,ParameterDirection.Input,false,0,0,null,DataRowVersion.Current,strFname);
    SqlParameter pFileData=new SqlParameter("@Content",SqlDbType.Image,b.Length, ParameterDirection.Input, false,0,0, null, DataRowVersion.Current,b);
    SqlParameter pFileType=new SqlParameter("@ftype",SqlDbType.NVarChar,strFtype.Length, ParameterDirection.Input, false,0,0, null, DataRowVersion.Current,strFtype);
    SqlParameter pFileSize=new SqlParameter("@fsize",SqlDbType.Int,strFtype.Length, ParameterDirection.Input, false,0,0, null, DataRowVersion.Current,intFsize);

    cmd.Parameters.Add(pFileName);
    cmd.Parameters.Add(pFileData);
    cmd.Parameters.Add(pFileType);
    cmd.Parameters.Add(pFileSize);cmd.ExecuteNonQuery();con.Close();
    }
    else 
    {
    return;
    }