字节数组插入到sql中的varbinary列 [英] byte array insert to varbinary column in sql

查看:82
本文介绍了字节数组插入到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);
Where bytes is your byte array.


这篇关于字节数组插入到sql中的varbinary列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆