A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Connect to Access Database in Visual Studio .NET
This tutorial uses DataReaders to read the data from a Microsoft Access Database in Visual Studio .Net 2003. ASP.NET web application is used in this tutorial so at the end you will have a web page that derives its data from an Access database.
On Friday, January 6th 2006 at 04:17 PM
By Nabeel Akhtar (View Profile)
(Rated 4.6 with 57 votes)
This tutorial is available as a VIDEO in Flash Format. To access the video tutorial, click here
You can use DataSets or DataReaders to read the information from the database. A DataReader is about twice as fast as a DataSet (according to Sams Publication). This tutorial uses DataReaders to read the data from a Microsoft Access Database
in Visual Studio .Net 2003. ASP.NET web application is used in this tutorial so at the end you will have a web page that derives its data from an Access database.
Following are screen-shots along with some description but I recommend you view the VIDEO TUTORIAL.
Open up Visual Studio .NET 2003 and click on New Project on the Start page:
In the New Project window select Visual Basic Projects on the left side and click on ASP.NET Web Application on the right.
Assign a location in the location tab and click OK to continue
When the web form opens up, click on the Server Explorer tab at the left:
Right click on Data Connections and select Add Connection...
Under the Provider tab, select Microsoft Jet 4.0 OLE DB Provider. You will use this to connect to an Access database. If you have a SQL database, make sure you select the right provider from this list. Click on Next to continue
Under the Connection tab, select the ... button to select the database you are connecting to.
Once the location to the database has been defined, click on the Test Connection button make sure your database is visible to the application.
From the Toolbox menu look under the Data tab and click on OleDbConnection. Once clicked, click on the white space of your project. You can also drag and drop this to the white space.
Right click on the OleDbConnection1 in your project area and select Properties.
In the ConnectionString field, click on the drop-down button and select the database path that shows up. This creates a connection to the database in our project.
Next we need to set a command for this database that will query the database and bring back data. For this we will need to use the
OledbCommand object. Select it and click on the white are in your project window.
Right click on OleDbCommand1 object in your project window and click on Properties. In the CommandTextfield, type in your select statement
(e.g. Select * FROM tablename WHERE column1 = 'somevalue' )
Before you close the properties, there is one more thing you need to do. You need to tell the application that this command is associated with the database connection we created earlier. To do this, select the Connection field and expand the Existing option to see the OleDbconnection1 we created. Click on it to select it.
Now we have all the objects that we needed to define the database parameters. Its not time to create a DataGrid that will display the data in our web page. To do that, select the DataGrid option under the Web Forms tab and draw a window in your project area (simply click and drag).
Double click anywhere in the project window to view the code for this page. When the code window comes up, type in the code as shown in the following image:
Go back to the project view and click on the RUN button to run the code. The results from the database will show up in a web page.
I hope this helps.
|Digg It! Del.icio.us Reddit StumbleIt Newsvine Furl BlinkList|
Rate this tutorial
There are no related tutorials.
Related Source Code
There is no related source code.
ASP.NET Job Search
From the creators of Geekpedia, a revolutionary new coupon website!
BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.