Expand|Select|Wrap|Line Numbers
- public DataTable GetBooks()
- {
- string SQL = "Select * From Products";
- SqlConnection cnn = new SqlConnection(strConnection);
- SqlCommand cmd = new SqlCommand(SQL, cnn);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataTable dtProduct = new DataTable();
- try
- {
- if (cnn.State == ConnectionState.Closed)
- {
- cnn.Open();
- }
- da.Fill(dtProduct);
- }
- catch (SqlException se)
- {
- throw new Exception(se.Message);
- }
- finally
- {
- cnn.Close();
- }
- return dtProduct;
- }