Web Site Creator Web Hosting Help
   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

Sign Up Now! Overview

Questions? Call sales at
1 (425) 274-4500
Or try our
Visit our Help Center where you can get simple and quick product support.
   is an affiliate of   , a leading domain name services company.
Copyright © 1998-2018 Enom LLC. All rights reserved. Terms & Conditions | Privacy Policy | Abuse Policy