Click here to Skip to main content
15,896,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

i have a
picture field 
by type
varbinary(MAX)

now i want to read this field by DataTable (no DataReader) and put it to file.

here is code:
System.IO.FileStream File = new System.IO.FileStream("C:\\TempFile\\" + myPictureFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
            byte[] bytFile = new byte[File.Length + 1];
            bytFile = (byte[])(Dataset_11.Tables["my_test_table"].Columns["PictureFile"]);  
            File.Write(bytFile, 0, bytFile.Length - 1);
            File.Close();



the line:
bytFile = (byte[])(Dataset_11.Tables["my_test_table"].Columns["PictureFile"]);

is not correct. how should i change this line?
thanks

What I have tried:

i couldn't do anythings for do it.

help
Posted
Updated 3-Jan-19 11:54am

1 solution

As far as I can see, you only refer to a specific column of a specific DataTable. However, you don't define the row the data is coming from. In order to get the byte data from the data table you should refer to an existing row.

Consider following pseudo example
C#
foreach(DataRow row in Dataset_11.Tables["my_test_table"].Rows) {
   bytedata = row["PictureFile"];
   ...
}
 
Share this answer
 
Comments
Member 13522501 4-Jan-19 1:29am    
thanks. but above code put all picture field. i want only field of current record.

how?
Maciej Los 4-Jan-19 6:26am    
What you mean by current record?
Wendelius 4-Jan-19 11:09am    
In your post you don't explain what is the current record for you or how it would be selected so based on the information at hand it's impossible to answer.

However, in general you can for example use DataTable.Select Method (System.Data) | Microsoft Docs[^] to fetch a row or a set of rows but as said, without more information it's hard to tell if that is a feasible approach.
Maciej Los 4-Jan-19 6:26am    
5ed!
Wendelius 4-Jan-19 11:15am    
Thank you!

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