Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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



C#
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);
Posted
Updated 6-Sep-15 23:55pm
v3

1 solution

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.
 
Share this answer
 
Comments
Lalyka 7-Sep-15 4:39am    
This is correct thanks.but how can I add the next blolb I receive to the present one and update my table?
Thanks
Zoltán Zörgő 7-Sep-15 5:07am    
Looks simple: concatenate the two arrays
var z = new int[x.Length + y.Length];
x.CopyTo(z, 0);
y.CopyTo(z, x.Length);
Lalyka 7-Sep-15 5:55am    
I Updated my Question. thanks a lot for your time
Lalyka 7-Sep-15 5:21am    
grazie Zoltan and how to update after? because then after check the table there is nothing written inside
I tried to do FileList.InsertOnSubmit(wfl); but not working, no result

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900