problems retrieving data from an access database using vb.net 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ray Nimmo
    New Member
    • Apr 2006
    • 1

    #1

    problems retrieving data from an access database using vb.net 2003

    This is driving me nuts, been at it now for the last week, anyone any ideas on wher im going wrong?

    using a list box pipeLB and a date/time picker pDate, im trying to populate the list box with the rows from the database where the date equals the one selected on the date/time picker. This should happen when i click the button showData.

    my database is called PressureReading s and the table inside it is called Pipe1Readings, with columns labelled as key,date and pressure. All it keeps throwing is the exception, but i know the database isnt in use as it tells me, it must be in my code somewhere.

    heres my code;

    Code:
     
    Private Sub showData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles showData.Click
    Dim fmtStr As String = "{0,8} {1,15} {2,15} " 
    Dim i As Integer
    Dim tdate As Date
    tdate = FormatDateTime(Me.pDate.Value, DateFormat.ShortDate)
    'Place contents of Pressures table into a DataTable
    Dim dt As New DataTable
    Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = PressureReadings.mdb "
    Dim sqlStr As String = "SELECT * FROM Pipe1Readings" ' where date = #" + tdate + "#"
    Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
    Try
    dataAdapter.Fill(dt)
    Catch
    MsgBox("Database Currently in Use - Can't Open")
    ' End
    End Try
    dataAdapter.Dispose()
    'Fill the list box
    pipeLB.Items.Add(String.Format(fmtStr, "DATE", "PRESSURE", "KEY"))
    For i = 0 To dt.Rows.Count - 1
    pipeLB.Items.Add(String.Format(fmtStr, FormatDateTime(dt.Rows(i)(0), _
    DateFormat.ShortDate), dt.Rows(i)(1), dt.Rows(i)(2)))
    Next
    End Sub
    any help would be most appreciated

    sorry about the low points - trying to conserve them - waiting for the student loan cheque to come in so i can buy some more.

    again - much appreciated in advance.

    Ray
    Last edited by Niheel; Apr 22 '06, 11:01 PM.
  • zandries1234
    New Member
    • Apr 2006
    • 2

    #2
    I think your connection string is wrong or giving trouble.
    I have coppied your code added a few lines and got it to work.

    connStr = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=C:\Thefo lder\thefilenam e.mdb;User Id=admin;Passwo rd=;"
    Dim mycon As New System.Data.Ole Db.OleDbConnect ion(connStr)

    Dim sqlStr As String = "SELECT * FROM temptable"
    Dim dataAdapter As New OleDb.OleDbData Adapter(sqlStr, mycon)

    I basically changed your connection string and first created the connection and then the adapter using a connector rather than a connection string. Makes it easier to debug.

    Comment

    Working...