Free templates
Meny Search Free templates

SELECT from MS SQL database (C#, VB and ASP.NET) | Free code

Here you can download free code (C# and VB) to retrieve data from a Microsoft SQL database using the SELECT statement and then present information on a web page using the selected data.

Code to SELECT from a MS SQL database makes it possible for you to retrieve data from one or more tables in a database and to make calculations on the data. Using SELECT, you can retrieve data from multiple related tables that are linked on primary keys and foreign keys.

The purpose of a SELECT from a MS SQL database is many times to present information on a website and there are different approaches for presenting information from a database. In this template, we present four different approaches to handle a SELECT statement.

The first approach is that we choose only one value from a table in a MS SQL database and present a comparison in a label. The second approach is that we use a "SqlDataReader" to present data in a "repeater". The third approach is that we use a "SqlDataReader" to present one row of data in a form and the fourth approach is that we are using a "DataSet" to present grouped data in a "repeater".

This code to retrieve data from a MS SQL database is divided into two files, an aspx page where information from the database are presented and a code page (C# or VB) that contains code for the SQL SELECT statements. The web page for the web form is not connected to a "master page", a web project should contain a "master page" that is linked to CSS files so that it becomes easy to maintain the web design for the entire website.

Before you can retrieve data from a MS SQL database, you must have created a database, tables in the database and a named connection string to the database in the "Web.config" file. In this template we have created a connection string to the MS SQL database with the name of "ConnectionString" and it is this connection string that we reference to before we execute SQL statements.

The code for the SELECT statements is surrounded by a "Try/Catch/Finally" block and this means that any errors in the code are handled by the web application, it is good to avoid to let errors be handled by the web server for a web host for example.

Remember that you in your web hosting account must have made a setting for the correct version of "ASP.NET" on your website (the version listed in the file "Web.config"). We are using Visual Web Developer 2005 (2010) Express Edition for web programming.
Updated: 01-01-2015 | Created by

Download SELECT from MS SQL database (C#, VB and ASP.NET) | Free code ยป

Tags: sql database code