Database Connection Sample

Discussion in 'ASP.NET / ASP.NET Core' started by Bruce, Feb 10, 2003.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Bruce

    Bruce DiscountASP.NET Staff

    As requested by some users, i am providing a very simple database connection sample.

    <%@ Page Language="VB" %>
    <%@ import Namespace="System.Data" %>
    <%@ import Namespace="System.Data.OleDb" %>
    <%@ import Namespace="System.IO" %>
    <script runat="server">

    Sub Page_Load


    Dim conn as OleDbConnection
    Dim cmd as OleDbCommand
    Dim dbReader as OleDbDataReader
    Dim result as string

    ' Create Connection using OLEDB
    conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\test.mdb"))
    Dim strSQL as string = "select * from customers"

    conn.open()
    cmd = new OleDbcommand(strSQL,conn)
    dbReader = cmd.executereader

    ' Bind result to repeater control
    repeater1.datasource = dbReader
    repeater1.databind()

    ' Close Connections
    dbReader.close()
    conn.close()


    End Sub

    </script>
    <html>
    <head>
    </head>

    <form runat="server">
    <h1>Simple Application to retrieve &amp; display data using DataReader Control
    </h1>
    <p>
    This page contains a simple application to retrieve data from an Access database and
    displaying it using Datareader &amp; repeater control. (<a href="retrievedata1_source.htm">source
    code</a>)
    </p>
    <p>
    <asp:Repeater id="Repeater1" runat="server">
    <HeaderTemplate>
    <table border="0">
    <tr bgcolor="#C0FFC0">
    <th>
    Name</th>
    <th>
    Address</th>
    <th>
    City</th>
    <th>
    State</th>
    <th>
    Zip</th>
    <th>
    Country</th>
    </tr>
    </HeaderTemplate>
    <itemTemplate>
    <tr>
    <td>
    <%# container.dataItem("name") %></td>
    <td>
    <%# container.dataItem("address") %></td>
    <td>
    <%# container.dataItem("city") %></td>
    <td>
    <%# container.dataItem("state") %></td>
    <td>
    <%# container.dataItem("zip") %></td>
    <td>
    <%# container.dataItem("country") %></td>
    </tr>
    </itemtemplate>
    <FooterTemplate>
    </table>
    </FooterTemplate>
    </asp:Repeater>

    </p>
    </form>
    </body>
    </html>
     
  2. The statement "Dim conn as OleDbConnection" causes error in my page.

    Microsoft VBScript compilation error '800a0401'

    Expected end of statement

    /new/db_test.asp, line 10

    Dim Conn as OleDbConnection
    ---------^
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    You need to import the

    system.data.oledb namespace


    quote:Originally posted by pupu79

    The statement "Dim conn as OleDbConnection" causes error in my page.

    Microsoft VBScript compilation error '800a0401'

    Expected end of statement

    /new/db_test.asp, line 10

    Dim Conn as OleDbConnection
    ---------^

    </blockquote id="quote"></font id="quote">
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page