Question

I'm trying to make a very simple application that connects to an Access 2003 database. I built a very simple user interface with 7 labels and 7 text-box with only 2 buttons: one of them is "Save" and the other one is "Exit".

Inside my form I added the code :

Imports System.Data
Imports System.Data.OleDb

Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, 
              ByVal e As System.EventArgs) Handles Button1.Click
    'Try
    Dim saveinto As New OleDb.OleDbCommand
    Dim constr As String = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "db.mdb"
    Dim conn As New OleDb.OleDbConnection(constr)
    saveinto.Connection = conn
    saveinto.CommandType = CommandType.Text
    saveinto.CommandText = " insert into users(id,username,nid,money,mode,help,yesorno) " & " values ('" & TextBox7.Text & "' ,'" & TextBox1.Text & "' , '" & TextBox2.Text & "','" & TextBox3.Text & "' , '" & TextBox4.Text & "' , '" & TextBox5.Text & "' , '" & TextBox6.Text & "')"
    conn.Open()
    saveinto.ExecuteNonQuery()
    conn.Close()
    MsgBox("All Done :P ")
            Exit Sub

End Sub

when i press the Save Button i got that error :

A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll`

and its the first time to see it, i thought that something wrong in my system (WinVista:) or database (build with my Access 2007 then converted to 2003) and i uninstall Access 2007 and install 2003 then rebuild new database and replace the old one with it.

When i run my app and press the Save Button i got the same error Message with

OledbException was unhandled Could not find file 'C:\Users\Mahmoud\Documents\Visual Studio 2008\Projects\Test\Test\bin\Debugdb.mdb.

i searched here before asking my question for my problem but i couldn't find the same problem and and i tried to apply some suggestions from similar errors but nothing happened so forgive me if duplicated a question and please HELP. thanks

No correct solution

OTHER TIPS

It appears that Application.StartupPath returns

C:\Users\Mahmoud\Documents\Visual Studio 2008\Projects\Test\Test\bin\Debug

and that does not have a trailing backslash (\), so when you append db.mdb to it you get a path that does not actually point to your database file. Try

... Application.StartupPath & "\db.mdb"

instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top