1
Answer

get byte[] from a database

gamedev

gamedev

20y
1.9k
1
I've saved an image (converting in byte[]) inside a field of my database, now i would read the database getting these bytes[] and convertering into the original image... I use this code: OleDbDataReader myReader; .... .. instance myReader here... .... myCommand.ExecuteReader(); MemoryStream myStream; int buffersize = 300000; // doubt n°2 = but if my image is bigger of 300000 ??? Byte[] outbyte = new Byte[299999]; myStream = new MemoryStream(outbyte, 0, 300000, true); myReader.GetBytes(5, 0, outbyte, 0, buffersize); myStream.Flush(); // am i just deleting all bytes unused? pictureBox1.Image = Image.FromStream(myStream); myStream.Close(); but this code doesn't work, where do i wrong? Then I've tried to change the code in this way: MemoryStream myStream; Byte[] outbyte = (Byte[])myReader["Image"]; myStream = new MemoryStream(outbyte); pictureBox1.Image = Image.FromStream(myStream); myStream.Close(); but this doesn't work too.
Answers (1)
0
Ankit Sharma

Ankit Sharma

NA 8.8k 141k 7y
Hi kalyan
 
Please refer to this link
 
https://stackoverflow.com/questions/15129665/how-to-get-the-count-of-records-in-the-datasource-of-the-gridview 
Accepted
0
Gautam Parmar

Gautam Parmar

NA 872 2.2k 7y
Hi Kalyan,
 You may try below code whether it is paging or not once row will bind it will count...
  1. int totalRow= 0;      
  2. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)      
  3. {      
  4.     if (e.Row.RowType == DataControlRowType.DataRow)      
  5.     {      
  6.         totalRow+=1;  
  7.     }      
  8.       
  9. }     
 
 
Next Recommended Forum