Intro
I have found many different ways on the internet and in books on how to accomplish the simple tasks of inserting, updating and retrieving values in a SQL database. Unfortunately most of the articles, posts, forums etc... that talk about this seem to give long drawn out instructions that sometimes work and sometimes do not.
Don't get me wrong, many of the resources I found were getting the task done but most of them wanted you to code the connection to the database all in C#. This is a step that is not necessary, this article will provide you with the small amount of code required to insert, update and retrieve values with up to date methods in Visual Studio.
First off is Inserting
- Drop a SQLDataSource control onto the page
- Configure the data source (connect it to the database, select columns etc...)
- All you need for the code behind is the following code (no extra imports needed)
Code
Listing 1: Inserting
Second is Updating/Selecting
- I combined the update and select examples together in a simple hit counter, and like I stated before by select I mean retrieving a value from the database using C#. In this example I retrieve a value and assign it to a variable. This hit counter, like I said above, is very simple, it will add another visitor even if they just refresh the page.
- Drop and configure SQLDataSource control onto the page
- Put the following in the code behind
Code
Listing 2: Updating/Selecting
Summary
That's all there is to it, this is an easy way to insert, update and retrieve values in a Microsoft SQL database using C# in Visual Studio. Feel free to use the above code, fix it up, or customize it, whatever you would like.
I hope that this helps.
About Chris Siermacheski
 |
www.electricalbuyandsell.com
View complete profile here.
|
You might also be interested in the following related blog posts
ASP.NET Data Control Events
read more
Did you know? There are many ways to insert a snippet into your code (Lisa Feigenbaum)
read more
Announcing the Web Platform Installer Release Candidate!
read more
OUTPUTing Data from the Just-Inserted, Updated, or Deleted Row(s)
read more
LINQ to SQL Dynamic Mapping
read more
Free Download: VS 2008 Database Edition Power Tools
read more
SqlNetFramework an easier alternative to microsoft data application block
read more
Building Interactive User Interfaces with Microsoft ASP.NET AJAX: Using the UpdatePanel
read more
How to debug a stored procedure in your Sql Server 2005
read more
The SQL Data Tools in Orcas
read more
|
|
Please login to rate or to leave a comment.