Asp.net 使用LINQ将附件上载到sql server

Asp.net 使用LINQ将附件上载到sql server,asp.net,sql-server,attachment,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 (DataContextData

将文件从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));
} 
public bool AttachmentInsert(int-mimeTypeId,string-attachFileName,
字节[]附件内容)
{
使用(DataContextDataContext dc=conn.GetContext())
{ 
int attachId=(int)dc.spAttachment\u Insert(mimeTypeId,attachFileName,
附件内容)返回值;
如果(附件!=0)
{
返回true;
}
返回false;
}
}
[函数(Name=“dbo.spAttachment\u Insert”)]
public ISingleResult spAttachment_Insert(Name=“AttachContent”,DbType=“VarBinary(1)”)]System.Data.Linq.Binary AttachContent,
{
IExecuteResult结果=
this.ExecuteMethodCall(this,((MethodInfo)(MethodInfo.GetCurrentMethod()),
mimeTypeID、attachFileName、attachContent);
返回((IsingResult)(result.ReturnValue));
} 
任何帮助如何纠正

DbType="VarBinary(1)"
您正在将内容截断为1字节。改用
VarBinary(max)


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

简化:为什么不直接使用
return(attachId!=0)-似乎比您现在拥有的要简单得多。。。。(我知道这并不能解决您的问题-只是旁敲侧击)简化:为什么不直接使用
return(attachId!=0)-似乎比您现在拥有的要简单得多。。。。(我知道,这并不能解决你的问题——只是旁敲侧击)