Public Class Form1

Inherits System.Windows.Forms.Form
Dim con As New OleDb.OleDbConnection
Dim dbprovider As String
Dim dbsource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim run = New OleDb.OleDbCommand
Dim sql As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

dbprovider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbsource = "Data Source = C:\Documents and Settings\aditya\My Documents\project.mdb"

con.ConnectionString = dbprovider & dbsource
con.Open()

sql = "INSERT INTO user values('1','aditya','goel')"
da = New OleDb.OleDbDataAdapter(sql, con)
run = New OleDb.OleDbCommand(sql, con)
run.ExecuteNonQuery()


ABOVE CODE GIVES THE FOLLOWING ERROR WHEN I RUN IT.....:-
"An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

Additional information: Exception has been thrown by the target of an invocation."

dbprovider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbsource = "Data Source = C:\Documents and Settings\aditya\My Documents\project.mdb"

your connectionstring should look like this:

Dim dbsource as string = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Emp.mdb;")
        
dbsource.Open()

'other codes to follow
sql = "INSERT INTO user values('1','aditya','goel')"
da = New OleDb.OleDbDataAdapter(sql, con)
run = New OleDb.OleDbCommand(sql, con)
run.ExecuteNonQuery()

not helping it is still giving error on oledbconnection.
somebody please help.

my code is able to build a connection,which i have come to know by debugging.....
i guess something is wrong with the sql query.

From the values you're putting into the table, what does '1' stand for? are you using an auto-increment ID in the database or you insert at will?

better still, it appears you want to keep log of every user that logs into your application. If am right, i would advise you create a login form so that users can enter their username and password. that way, you can now save the user information on every successful login

yes 1 is the auto incremented id....
and also i just have to enter the first name and the second name in a table which has been created by me in the database "project.mdb"
the name of the table is "user"......

since the ID field is auto-increment, you cant add an ID to the query so remove the ID in the query and just leave the rest. The database would automatically assign an ID to any new entries.

thanx all......
actually i have found a very minor error regarding this problem...
actually while writing the sql query, we have to enclose the table name within bracktes i.e[],
which makes the sql query to be:-
SELECT * FROM [user].
try it its working:)

This question has already been answered. Start a new discussion instead.