Results 1 to 14 of 14

Thread: RESOLVED: Learning databases, problem with tutorial: VB.NET 2005

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    34

    Question RESOLVED: Learning databases, problem with tutorial: VB.NET 2005

    I'm trying to get the hang of .NET databases, after having a decent grasp of them in VB 5.0. It's a new animal, though, so I'm starting with a fresh mindset.

    I found this tutorial by Mendhak,
    http://www.vbforums.com/showthread.p...8-Tutorial-%29
    but when I try it, I get an error

    Error 2 Name 'conn' is not declared. ...

    which seems to refer to the line in the tutorial

    conn.connectionstring = "provider=microsoft.jet.oledb.4.0;datasource=c:\sample.mdb;user=Admin;password=;"

    so I inserted this line just above it:

    Dim conn As New OleDbConnection 'trying to declare "conn" to clear an error

    Which clears that error, but on trying to run/debug (page 2 of tutorial) I get an error which highlights the line

    da.Fill(ds)

    The entire code section looks like this:

    Imports System.Data.OleDb
    Public Class Form1
    Dim ds As New DataSet
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim conn As New OleDbConnection 'trying to declare "conn" to clear an error
    conn.ConnectionString = "provider=microsoft.jet.oledb.4.0;datasource=c:\sample.mdb;user=Admin;password=;"
    Dim strsql As String = "select employeeID, FirstName, LastName, Location from tbl_master"
    Dim da As New OleDbDataAdapter(strsql, conn)
    da.Fill(ds)
    If ds.Tables(0).Rows.Count > 0 Then
    TextFirst.Text = ds.Tables(0).Rows(0).Item("FirstName").ToString()
    TextFirst.Text = ds.Tables(0).Rows(0).Item("LastName").ToString()
    TextFirst.Text = ds.Tables(0).Rows(0).Item("Location").ToString()
    TextFirst.Text = ds.Tables(0).Rows(0).Item("EmployeeID").ToString()
    End If
    End Sub
    End Class


    I did download the sample.mdb file, and placed it at c:\sample.mdb, as I have referenced it above.

    Any advice or comments would be welcome.
    Last edited by Og_ofthejungle; Nov 27th, 2012 at 09:10 PM. Reason: RESOLVED by using VBA instead

Tags for this Thread

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