Bind Datagrid

sundar k replied to touseef ahmed at 11-May-08 10:50

Your code look something like this,

// function to bind the records retrieved
// from the database to the "dgtemp" datagrid
void BindGrid()
{
       // build the connection string
       string strConn = "user id=sa;password=sa;";
       strConn += "initial catalog=pubs;data source=mydbserver;";
   
       // connect to the database
       SqlConnection objConn = new SqlConnection(strConn);

       // query
       string strSQL = "SELECT * FROM yourtable";

       // create an instance of the DataReader object
       SqlCommand objCommand = new SqlCommand(strSQL, objConn);
       objConn.Open();

       SqlDataReader objReader = objCommand.ExecuteReader();

       // assign the DataReader object as the source
       // for the "dgtemp" datagrid, we can set the dataset also...

       dgtemp.DataSource = objReader;

       dgtemp.DataBind();

       // free up memory
       objReader.Close(); 
}




Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
  datagrid or dataview send the data to dataset or datatable.. - touseef ahmed  12-May-08 03:55 3:55:39 AM
      Use the DataTable as the DataSource. - Peter Bromberg  11-May-08 05:05 5:05:30 PM
      Bind Datagrid - sundar k  11-May-08 10:50 10:50:59 PM
      DataGrid sending data - Sanjay Verma  11-May-08 11:53 11:53:50 PM
      Check here - santhosh kapa  12-May-08 12:05 12:05:35 AM
      Try This - Sujit Patil  12-May-08 12:26 12:26:53 AM
      Check this - Chirag Bhavsar  12-May-08 12:57 12:57:58 AM
      Have a look at this - chakradhar koturu  12-May-08 01:09 1:09:29 AM
View Posts