Click here to Skip to main content
11,580,350 members (76,208 online)
Click here to Skip to main content

An Easy Way To Query a Database

, 14 Feb 2011 CPOL 1.3K 1
Rate this:
Please Sign up or sign in to vote.
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?
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)

Share

About the Author

FZelle
Web Developer
Germany Germany
Software-Developer since 1990
Specialiced in LAN/WAN Tracers ( sniffer )
now developing in .NET ( c#, VB, ASP ..)

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 15 Feb 2011
Article Copyright 2011 by FZelle
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid