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;
try
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(query, con);
da.Fill(ds);
}
catch (Exception ex)
{
ds = null;
}
finally
{
if (con.State == ConnectionState.Open) con.Close();
}
return ds;
}
Is this a secure or good way to run queries in the database from c#?
I have read about queries with parameters. How I can do this using parameters?