Click here to Skip to main content
Click here to Skip to main content

An Easy Way To Query a Database

By , 14 Feb 2011

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

23 Feb 2011  
PrimeCoder
 
Nice,How about adding a couple of other methodspublic static void Parameter(IDbCommand command, string naam, object value){ IDbDataParameter par = command.CreateParameter(); par.ParameterName = naam; par.Value = value ?? DBNull.Value; ...
29 Apr 2011  
dot net tech 4 alternatives  
 
An Easy Way To Query a Database
14 Feb 2011  
FZelle
 
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)) { ...
14 Feb 2011  
woric
 
The sample code provided by Andrew Rissing is a huge improvement over the original, but incorrectly catches the exception and displays a MessageBox. (Andrew correctly points out this is not a good idea.)A better solution is to allow the exception to fail:public DataSet...

License

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

About the Author

Andrew Rissing
Software Developer (Senior)
United States United States
Since I've begun my profession as a software developer, I've learned one important fact - change is inevitable. Requirements change, code changes, and life changes.
 
So..If you're not moving forward, you're moving backwards.

| | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 14 Feb 2011
Article Copyright 2011 by Andrew Rissing
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid