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(); }
|
|