jump to navigation

Getting our hands dirty (utility methods) November 6, 2006

Posted by _netoLopez in .net, c#, database, mlists, mssql, programming, projects, web2.0.

Hello everybody!, to continue with this “blog-project”, I decided to go with .net 2005 [framework 2.0] (c#) and msSql Server 2005 express edition.

I’ll start by showing two methods I like using to access databases when I’m not relying on stored procedures or any other fancy rdbms stuff…

The first one is GetDataTable() and the second one is Execute()…  These methods are SQLServer2005 specific, but can be made more generic using System.Data.OleDb. They are very handy for quick-and-dirty projects :mrgreen:

{pardon the code display, but wordpress has been stripping all my html and I didn’t like how this template shows code 😀 }

GetDataTable() returns a System.Data.DataTable; this method will take a SELECT statement to run against your database and will return a DataTable which you can use as you please. Personally, you’ll never see me using a DataGridView object on my projects 😉 . Click here for code.

Execute() returns an integer stating how many rows were affected by the sql statement. It requires you to supply one of the following types of statement: INSERT or UPDATE or DELETE. Click here for code.

Only thing to note on these two methods is they use a web.config appSetting key to get their connectionString. We’ll see the web.config file later.



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: