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.   
  5. try  
  6. {  
  7.        Conn.Open();  
  8.        SqlCommand Cmd = new SqlCommand(commandString, Conn);  
  9.        rdr = Cmd.ExecuteReader();  
  10.   
  11.        MasterCustView.DataSource = rdr;  
  12.        MasterCustView.DataBind();  
  13. }  
  14. catch (Exception ex)  
  15. {  
  16.      // Log error  
  17. }  
  18. finally  
  19. {  
  20.     if (rdr != null)  
  21.     {  
  22.         rdr.Close();  
  23.     }  
  24.     if (Conn != null)  
  25.     {  
  26.         Conn.Close();  
  27.     }  
  28.  }