get byte[] from a database
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
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
Hi Kalyan,
You may try below code whether it is paging or not once row will bind it will count...
- int totalRow= 0;
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- totalRow+=1;
- }
-
- }