Set The Gridview’s Datasource Property And Simply Call The Databind Method

  1. SqlConnection Conn = new SqlConnection(“Data Source=Localhost\\SQLEXPRESS;Initial Catalog=Flash2;Integrated Security=True;”);
  2. SqlDataReader rdr = null;
  3. string commandString = “SELECT * FROM USER_MASTER”;
  4. try
  5. {
  6.        Conn.Open();
  7.        SqlCommand Cmd = new SqlCommand(commandString, Conn);
  8.        rdr = Cmd.ExecuteReader();
  9.        MasterCustView.DataSource = rdr;
  10.        MasterCustView.DataBind();
  11. }
  12. catch (Exception ex)
  13. {
  14.      // Log error
  15. }
  16. finally
  17. {
  18.     if (rdr != null)
  19.     {
  20.         rdr.Close();
  21.     }
  22.     if (Conn != null)
  23.     {
  24.         Conn.Close();
  25.     }
  26.  }

Leave a Reply

Your email address will not be published. Required fields are marked *