字节数组插入到sql中的varbinary列
嗨
我想将我的byte [](字节数组)插入我的表(Data)中的一个列,其类型为varbinary(max),我需要能够在以后下载数据,所以我不希望它被更改。
任何人都可以帮助我如何在我的数据库中插入缓冲区并更新它?我使用过Buffer.BlockCopy(buffer,0,fl.Data,offset,count);但fl.Data varbinary类型doed与Buffer.BlockCopy的要求不匹配
我还需要在每次新作品到达时将缓冲区连接到Data。并更新表格
Hi
I want to insert my byte[] (byte array) to a column in my table (Data) which its type is varbinary(max) and I need to be able to download the data later so I don't want it to be changed.
Can anybody help me how can I insert buffer in my db and update it? I have used Buffer.BlockCopy(buffer,0,fl.Data,offset,count); but fl.Data varbinary type doed not match teh requirements of Buffer.BlockCopy
I also need to concat the buffer to "Data" each time a new piece arrives. and update the table
public Boolean WriteBlobsToDB(byte[] buffer,int offset,int id,string fileName,string fileType,string user,string md5){
bool ok = false;
FileList fl = new FileList(); //FileList is the name of my table
fl.Id = id;
fl.FileName = fileName;
fl.FileType = fileType;
fl.MD5 = md5;
fl.UserID = user;
Buffer.BlockCopy(buffer,0,fl.Data,offset,count);
如果我是对的,你的数据字段是System.Data.Linq.Binary类型。
你可以这样赋值:fl.Data = new System.Data.Linq.Binary(bytes);
其中bytes
是你的字节数组。
If I am right, your Data field is of type System.Data.Linq.Binary.
You can assign value like this:fl.Data = new System.Data.Linq.Binary(bytes);
Wherebytes
is your byte array.