Click here to Skip to main content
12,953,230 members (61,565 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 14 Feb 2011

An Easy Way To Query a Database

, 14 Feb 2011 CPOL
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...


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

14 Feb 2011
Andrew Rissing
The following samples should take advantage of using statements and furthermore built in features of the ADO.NET framework. Furthermore, if you open a connection, make sure you open it at the latest time possible and close it as soon as possible.Edit: While I was originally not trying to...
23 Feb 2011
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
4 alternatives  
An Easy Way To Query a Database
14 Feb 2011
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)) { ...


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


About the Author

Web Developer
Australia Australia
I am a C#/XML developer with almost 10 years professional web development experience and over 15 years experience with Client Server applications.

In the past I wrote ISAPI dlls, but these days I stick to ASP.NET, AJAX and CSS based designs.

Favourite Technologies: C#, XSLT, NUnit.

Pet Hates: Webforms are evil. Developers who cannot write their own HTML shouldn't develop websites. (Seriously, websites made with hand coded HTML/CSS by a decent web-coder are developed quicker and work better. If you can't learn to do it by hand then please stop fooling yourself.)

| | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 14 Feb 2011
Article Copyright 2011 by woric
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid