|
|
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
|
Clickhere to visit Microsoft's site for more details on accessing SQL Server using ASP.NET.
|
|
|