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

› Simple ASP Image Resize Function

› Install AJAX On Machines Running Visual Studio 2005

› ASP.Net Interview Questions And Their Answers

› Creating Pretty Popups Using AJAX

› Encode Url using ASP

› SQL Server Performance Counters

› .NET Data Access Performance Comparison

› UpdatePanel control in Asp.net Ajax

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
 
› Creating Tableless Sites - Why And Some Basics

› Encode Url using ASP

› UpdatePanel control in Asp.net Ajax

› Successful CSS Template Skins

› Understanding SQL Server Memory Internals

› Search Engine Friendly Web Design - 3 Ways To Use CSS

› Access Master Page controls from the Content Page - Asp.net

› How To Set Up A 301 Redirect On IIS

› List of all selected items in a CheckBoxList - Asp.net

› MySQL Join Tutorial

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