|
Home > Article > ASP.Net :: Database Select Advanced
|
ASP.Net :: Database Select Advanced |
Abstract :
Advanced versionof how to can connect to database within ASP.Net Framework |
Views :
11950
Published :
Friday, February 22, 2002
By
HyperLink
|
|
The code example below connects to an Access database, executes a SQL statement, and prints out the results. At the end of the code below I included how to get at a specific row. Results of the code follow below.
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
Dim oConnection As ADOConnection
Dim oCommand As ADODataSetCommand
Dim oDS As New DataSet
Dim sConnString As String
Dim sSQL As String
Dim nCount As Integer
'Define connection string
sConnString = "DRIVER={Microsoft Access Driver (*.mdb)}; " & _
"DBQ=" & Server.MapPath("\aspxexamples\database\test1.mdb")
sSQL = "SELECT * FROM test1"
'Create the connection
oConnection = New ADOConnection(sConnString)
'Execute this SQL statement with this Connection String
oCommand = New ADODataSetCommand(sSQL, sConnString)
'Fill the DataSet and name the table
oCommand.FillDataSet(oDS, "TestTable")
Response.Write("<font face=Arial size=2>")
Dim Row
nCount = 1
For Each Row In oDS.Tables("TestTable").Rows
Response.Write(nCount & ". " & Row(0) & " " & Row(1) & "<br>")
nCount = nCount + 1
Next
Response.Write("<br><br>")
Response.Write(oDS.Tables("TestTable").Rows(0)("FirstName") & _
"<br><br>")
End Sub
</script>
| The code prints out the following:
1. john doe
2. mary jane
3. sam smith
|
|
|
|
|
 |
Yasir
Send Feedback
Yasir is a .NET expert, with over 5 years experience in Microsoft Technologies, 8 years overall programming experience, he is the owner, founder & primary contributor of Minwar.com, and he also works as IT Director in the hospitality industry.
|
|
|
|