Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...