public static DataTable GetCustomers(string state) { SqlConnection conn = CourseConnection.MMABooks(); SqlCommand selectCommand = new SqlCommand(); selectCommand.Connection = conn; selectCommand.CommandText = "Select * From Customers Where Region = @State"; selectCommand.Parameters.AddWithValue("@State", state); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = selectCommand; DataTable dt = new DataTable(); try { conn.Open(); da.Fill(dt); return(dt); } catch (Exception ex) { throw ex; } finally { conn.Close(); } }
public static SqlDataReader GetStates() { SqlConnection conn = CourseConnection.MMABooks(); string sql = "Select StateCode From States"; SqlCommand selectCommand = new SqlCommand(); selectCommand.Connection = conn; //selectCommand.CommandType = CommandType.StoredProcedure; //selectCommand.CommandText = "StoredProcName"; selectCommand.CommandText = sql; try { conn.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.CloseConnection); return(reader); } catch (Exception ex) { throw ex; } finally { //Clean Up //conn.Close(); } }