Become a domain reseller today! Learn More
1 (425) 274-4500

USING SQL WITH ADO.NET

To give your page access to the classes you will need to perform SQL data access, you must import the System.Data and System.Data.SqlClient namespaces into your page.

'Do not forget to import
'System.Data
'System.Data.SqlClient


Dim myDataReader As SqlDataReader
Dim mySqlConnection As SqlConnection
Dim mySqlCommand As SqlCommand

'your connection properties
Dim mydatabaseserver As String = "database1.ehost-services.com"
Dim mylogin As String = "yourlogin"
Dim mypassword As String = "yourpassword"

mySqlConnection = New SqlConnection("server=" & mydatabaseserver & ";password=" & mypassword & ";user id=" & mylogin)
mySqlCommand = New SqlCommand("SELECT col1, col2 FROM mytable", mySqlConnection)

'open connection
mySqlConnection.Open()
myDataReader = mySqlCommand.ExecuteReader(CommandBehavior.CloseConnection)

'loop records here
Do While (myDataReader.Read())
Response.Write("<br>col1=" & myDataReader.GetValue(0) & " and col2=" & myDataReader.GetValue(1))
Loop

' Always call Close when done reading.
If Not (myDataReader Is Nothing) Then
myDataReader.Close()
End If

' If connection is open then close it when done.
If (mySqlConnection.State = ConnectionState.Open) Then
mySqlConnection.Close()
End If

Click here to visit Microsoft's site for more details on accessing SQL Server using ASP.NET.
Questions? Call sales at
1 (425) 274-4500
Or try our
Visit our Help Center where you can get simple and quick product support.
Copyright © 1998 - 2012 eNom Inc. All rights reserved. Terms & Conditions | Privacy Policy
eNom Inc, Internet - Web Hosting, Kirkland, WA