I have the next code to run queries in the database in my system. :
public static DataSet execute_query(string query)
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection();
con.ConnectionString = DataAccessLayer.Properties.Settings.Default.cn;
SqlDataAdapter da = new SqlDataAdapter(query, con);
catch (Exception ex)
ds = null;
if (con.State == ConnectionState.Open) con.Close();
A few things I see that raise flags.
IList<>and call it a day. But by all means, use the DataSets (or DataTables) if you like.
usingstatement. You should dispose of objects implementing
IDisposable, the using statement is an easy way to to this. Had you separated the UnitOfWork from the Repository then I wouldn't mention this - as the UnitOfWork would be disposed of elsewhere.
To use parameters make a
SqlCommand object from your connection and query. In that object you can add parameters to the
Feed that to the