DataReader and DataGrid Binding

shahab

Junior Contributor
Joined
Aug 14, 2003
Messages
206
Location
Iran(Middle East)
Dear friends,
I have heard that it is possible to populate data Grid by DataReader,…
One-Is it possible at all?
Two-What is the exact code?
Cheers :D
 
Yes it is possible, you would use this method if you don't want data binding. (A few other reasons too :) )

I can't give you code, I'm sure someone else will.
 
Why are you trying to do this with a data reader instead of just using a datatable or dataset? (There are a lot of code examples out there for this)

A data reader is forward read only. I don't see any significant advantage of using a data reader?

I was just curious as to why you want to use a data reader.
 
You still have to use databind. I have left out the reader in the code, you really don't need it.


cmdSql = New SqlCommand(strSql, connSql)
dgMyGrid.Datasource = cmdSql.ExecuteReader
dgMyGrid.DataBind()


-lp
 
I find it at last:
void bindGrid1()
{

string strCon = ConfigurationSettings.AppSettings["ConnStr"];
SqlConnection objConn = new SqlConnection(strCon);

objConn.Open();

//Create a command object for the query
string strSQL =":)";

SqlCommand objCmd = new SqlCommand(strSQL, objConn);

//Create/Populate the DataReader;
SqlDataReader MyDR = objCmd.ExecuteReader();

DataGrid1.DataSource = MyDR;
DataGrid1.DataBind();
}
thanks to all
 
Back
Top