Results 1 to 2 of 2

Thread: ASP.net is killing me

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    6

    ASP.net is killing me

    I am just learning asp.net and Iwant to create a connection to an access database, retrieve data and display that in my page.
    I came across some tutorials, but they don't say where exactly the code should be placed. I really need step by step instructions. I have created an asp.net web application and am using a webform, where do I go from here?

    Any suggestions please?

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Here's one of about a million different ways of doing that:
    VB Code:
    1. <%@ Import Namespace = "System.Data" %>
    2. <%@ Import Namespace = "System.Data.OleDb" %>
    3. <script runat="server" language="vb">
    4. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    5.     If Not Page.IsPostBack Then
    6.         bindAuthors()
    7.     End If
    8. End Sub
    9. Protected Sub bindAuthors()
    10.     Dim mdbPath As String = "D:\AccessData\Biblio2002.mdb"
    11.     Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbPath
    12.     Dim cn As New OleDbConnection(connString)
    13.     Dim cmdText As String = "Select Top 100 * From Authors Order By Author"
    14.     Dim cmd As New OleDbCommand(cmdText, cn)
    15.     cmd.Connection.Open()
    16.     gridAuthors.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    17.     gridAuthors.DataBind()
    18. End Sub
    19. </script>
    20. <html>
    21.   <body>
    22.     <form runat="server">
    23.         <asp:DataGrid
    24.             Runat="server"
    25.             AutoGenerateColumns="True"
    26.             ID="gridAuthors"/> 
    27.     </form>
    28.   </body>
    29. </html>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width