Click here to Skip to main content
15,891,473 members
Articles / Programming Languages / Visual Basic

An Easy Way To Query a Database

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
14 Feb 2011CPOL 6.3K   3  
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...

Alternatives

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

Please Sign up or sign in to vote.
14 Feb 2011Andrew 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...
Please Sign up or sign in to vote.
23 Feb 2011PrimeCoder
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; ...
Please Sign up or sign in to vote.
29 Apr 2011dontumindit 4 alternatives  
An Easy Way To Query a Database
Please Sign up or sign in to vote.
14 Feb 2011FZelle
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)) { ...

License

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


Written By
Web Developer
Australia Australia
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Comments and Discussions