Question re-accessing my database..

kerbas10034

New member
Joined
Feb 21, 2013
Messages
2
Programming Experience
1-3
i copied my system from a CD and now it can not access the database....

error message.jpg

need feedback please..

thank you all
 
VB.NET:
#Region " #define "
    Private dbconn As New Odbc.OdbcConnection("Driver={Microsoft access Driver (*.mdb)};DBQ=" & Application.StartupPath & "\UCSH1.mdb")
    Private dbadapter As New Odbc.OdbcDataAdapter
    Private dbdataset As New DataSet
    Private userCommand As New Odbc.OdbcCommand
    Public pass As String
    Public result As Integer
#End Region
#Region " #Functions"
    Sub TEMPOS()
        dbadapter = New Odbc.OdbcDataAdapter("select * from login", dbconn)
        dbdataset.Clear()
        [B][U]dbadapter.Fill(dbdataset, "login")[/U][/B]
        Me.DataGridView1.DataSource = dbdataset.Tables("login").DefaultView
    End Sub
    Sub ShowMsg()
        MsgBox("Sorry, Incorrect UserName or Password" + vbCrLf + "Please try again...", MsgBoxStyle.Critical, "UCSH")
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox1.Focus()
    End Sub
#End Region
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim result As String
        Dim pass As String
        MAINFORM.PassedText = TextBox1.Text
        dbadapter = New Odbc.OdbcDataAdapter("Select * from login where Username like '" & Me.TextBox1.Text.Trim & "' and Password like '" & Me.TextBox2.Text.Trim & "%'", dbconn)
        dbdataset.Clear()
        dbadapter.Fill(dbdataset, "login")
        Me.DataGridView1.DataSource = dbdataset.Tables("login").DefaultView
        result = dbdataset.Tables("login").DefaultView.Count
        If result > 0 Then
            pass = dbdataset.Tables("login").DefaultView.Item(Me.DataGridView1.CurrentRow.Index).Item(2)
            If TextBox2.Text = pass Then
                Try
                    userCommand.CommandText = "insert into userlog values ('" & _
                        Label6.Text & "', '" & _
                       Label5.Text & "', '" & _
                       Me.TextBox1.Text.Trim & "', '" & _
                       Button1.Text & "')"
                    userCommand.Connection = dbconn
                    dbconn.Open()
                    userCommand.ExecuteReader()
                    dbconn.Close()
                Catch exp As Exception
                    MsgBox(exp.ToString())
                End Try
                Me.Close()
                MAINFORM.Show()
            Else
                ShowMsg()
            End If
        Else
            ShowMsg()
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
        End
    End Sub
    Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Try
            TEMPOS()
            TextBox1.Clear()
            TextBox2.Clear()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label6.Text = Date.Now.Date
        Label5.Text = Date.Now.TimeOfDay.ToString
    End Sub
sir this is the whole code,
the highlighted line for the error message is in the arrow...

thank you in advance...
 
Last edited by a moderator:
I have added
VB.NET:
 tags to your post to make the code snippet more readable.  Please do so for us yourself in future.[/I]

You should not be using ODBC for a start.  That should always be your last resort.  Use a data-source specific ADO.NET provider if one exists, otherwise use an OLE DB provider if one exists.  Only if neither of those is possible should you use an ODBC driver.  In this case, you should use OleDb for Access databases.

That said, it should still work with Odbc if you do it right.  Your code is looking in the same folder as your EXE for your MDB file and the error message is telling you that it can't find the file, so the solution is simple.

By the way, while I'm not sure that it works with Odbc, if you use OleDb there's no need to use string concatenation to get the folder path into the connection string.  Visit [url=http://www.connectionstrings.com]www.connectionstrings.com[/url] and check out the OLE DB connection string that uses |DataDirectory| to specify the folder path.
 
Back
Top