Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

An Easy Way To Query a Database

0.00/5 (No votes)
14 Feb 2011CPOL 4.8K  
You are both wrong with the DataAdapter.Why do you think there is an overload with the querystring and the connectionstring?public DataSet select_query(string query, string con_str){ try { using (SqlDataAdapter da = new SqlDataAdapter(query,con_str)) { ...
You are both wrong with the DataAdapter.
Why do you think there is an overload with the querystring and the connectionstring?
C#
public DataSet select_query(string query, string con_str)
{
  try
  {
         using (SqlDataAdapter da = new SqlDataAdapter(query,con_str))
         {
           DataSet ds = new DataSet();
           da.Fill(ds);  // Automatically opens/closes connection.
           return ds;
         }
       }
       catch (Exception ex)
       {
            MessageBox.Show(ex.Message);  // Bad mojo, but better than nothing I guess.
            return null;
       }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)