Reader get one row at a time
I have bit coneputal problem .
The SqlDataReader can only retrieve one row at a time from the data source and in order for it to get the next record, it has to maintain its connection to the data source..
string sSQL = "SELECT * FROM Products";
string sConnString =
"Server=(local);Database=Northwind;Integrated Security=SSPI;";
using (SqlConnection oCn = new SqlConnection(sConnString))
{
SqlCommand oSelCmd = new SqlCommand(sSQL, oCn);
oSelCmd.CommandType = CommandType.Text;
oCn.Open();
SqlDataReader oDr = oSelCmd.ExecuteReader();
DataGrid1.DataSource = oDr;
DataGrid1.DataBind();
}
if it get one row at a time then how it binds the data to grid if it contain one record at a time
Re: Reader get one row at a time
Thread moved from CodeBank forum (which is for you to post your code examples, not questions)
Re: Reader get one row at a time
The DataGrid just goes through each row in the datareader, and in each row, reads each column. It stores it in its own datasource and dynamically generates the corresponding rows and columns. It doesn't go 'back' when reading from the datareader. Internally, the databinding code may understand the type of the datareader and appropriately perform the 'while dr.read()'.