使用LINQ将附件上载到sql server

时间:2010-08-20 15:41:23

标签: asp.net sql-server attachment

将文件从asp.net上传到SQL Server 2008,上传到SQL Server后我看到附件内容为:0x89

我的存储过程接受:@AttachContent varbinary,

以下是我上传的代码。

public bool AttachmentInsert(int mimeTypeId, string attachFileName,
                             byte[] attachContent)
{
   using (DataContextDataContext dc = conn.GetContext())
   { 
      int attachId =  (int)dc.spAttachment_Insert(mimeTypeId, attachFileName, 
                                                  attachContent).ReturnValue; 
      if (attachId != 0)
      {
         return true;
      }
      return false;
   }
}

[Function(Name="dbo.spAttachment_Insert")]
public ISingleResult<spAttachment_InsertResult> spAttachment_Insert(Name="AttachContent", DbType="VarBinary(1)")] System.Data.Linq.Binary attachContent,        
{
   IExecuteResult result = 
       this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), 
                              mimeTypeID, attachFileName, attachContent);
   return ((ISingleResult<spAttachment_InsertResult>)(result.ReturnValue));
} 

任何帮助如何纠正。

1 个答案:

答案 0 :(得分:3)

DbType="VarBinary(1)"

您将内容截断为1个字节。请改用VarBinary(max)