Tips Station Asp.net Article Seo Articles
Tutorials Code Samples
›  Home
›  Mission
›  About us
›  Contact Us
›  Feedback
›  Terms & Condition
Asp Articles
IT Solutions
 
› ASP.NET

› Programming Tips

› Ajax

› Asp

› ADO.NET

› Databases

› SEO

› CSS And Designing

› Php

 
Most Viewed Articles
 
› Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

› Change theme dynamically without page refresh in ASP.NET

› Install AJAX On Machines Running Visual Studio 2005

› Creating Pretty Popups Using AJAX

› Simple ASP Image Resize Function

› SQL Server Performance Counters

› ASP.Net Interview Questions And Their Answers

› Encode Url using ASP

› Difference Between DataGrid and GridView in Asp.Net

› Select Specific Value WithIn Drop Down List Or Radio Button List

more...
 
 
Home> Programming Tips
 
ASP.NET Simple Connect To Database
 
I have been wondering what level of programming experience my blog readers have, my guess is some of them have a fair amount of knowledge but not too much, and thats why you are here, to get better.
Now if you are new to asp.net this might go over your head, but try to follow, and if you succeed in following this function you will also be able to use it. In this asp.net example you will see how to connect to a database and extract some data from it, then finally bind it to a datareader.

This is the real essence of server side language such as asp.net, connecting to database, saving from database etc. its how a lot of websites is build, and work with data.

Text with green color is the explanations you should follow to understand how the function works. But eventually you should be able to copy the function part and put it in your code, then call the function ConnectToDB define the select statement, username, password, server and database.

import System.Data
import System.Data.SqlClient
Function ConnectToDB(byval select_string, byval username as string, byval password as string, byval server as string, byval database as string)

this is declaring the sqlconnection, the sql command statement and the datareader

Dim connection_ As SqlConnection
Dim sqlcommand_ As SqlCommand
Dim SqlDataReader_ As SqlDataReader

Here we make the connection, put in the server adresse, login username, password and database

connection_ = New SqlConnection( "server=YOURSERVER;uid=username;pwd=password; " "database=YOURDATABASE")

Opening the connection

connection_.Open
cmdLath = New SqlCommand (select_string, connection_)
SqlDataReader_ = cmdLath.ExecuteReader
datareader.DataSource = rdrLath
datareader.DataBind

Always remember to close your connections, even though many servers auto close or has a timeout closing

SqlDataReader_.Close
sqlcommand_.Dispose
connection_.Close
End function
 
 
Vrp Technologies
 
Serversea Hosting
 
 
Latest Articles
 
› Sending SMS With PHP

› MySQL Join Tutorial

› Make An RSS Feed Using PHP

› Intro To Object: Option Variables

› Design An Online Chat Room With PHP And MySQL

› Create Tell A Friend Script With HTML & PHP

› Benchmark And Optimize PHP Script Speed

› What Kind of DBA Are You?

› SQL Server Performance Counters

› SQL Server Performance Tips

more...
 
Random Articles
 
› Difference Between DataGrid and GridView in Asp.Net

› Trapping Errors with the Err Object in ASP

› How to export a GridView to Excel - Asp.net

› How to crop an Image in Asp.Net

› SubRoutines vs. Functions - ASP

› Creating Pretty Popups Using AJAX

› ADO.NET Data Classes

› Make An RSS Feed Using PHP

› Displaying Data using ASP.NET 2.0 Repeater

› Understanding DDL Triggers In SQL Server 2005

more...
 
Home Mission About us Contact us Feedback Terms Conditions
2008 © Copyright TipsStation. All rights reserved.