0

I can't add infromation to my Projet.mdb ! please help me ! this is my code

Try


            Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =  C:\projet.mdb"

            Dim Save As New OleDbCommand
            Dim Conn As New OleDbConnection(ConStr)

            Save.CommandText = "INSERT INTO Client(Nom,Prenom,Adresse,Téléphone,date) VALUES(@p1,@p2,@p3,@p4,@p5)"
            Save.Parameters.AddWithValue("@p1", TextBox1.Text)
            Save.Parameters.AddWithValue("@p2", TextBox2.Text)
            Save.Parameters.AddWithValue("@p3", TextBox3.Text)
            Save.Parameters.AddWithValue("@p4", TextBox4.Text)
            Save.Parameters.AddWithValue("@p5", DateTimePicker1.Text)
            Save.Connection = Conn
            Conn.Open()
            Save.ExecuteNonQuery()
            MsgBox("Ajout réussi ")
            frm1.Show()
        Catch ex As Exception
            Exit Sub
        End Try
7
Contributors
8
Replies
9
Views
4 Years
Discussion Span
Last Post by Begginnerdev
0

Have you tried putting all of your connection items and actions before you do the parameters?

Edited by thines01

0

Example:

Dim Conn as New OledbConnection(ConStr)
con.Open()
Dim Save as New OledbCommand("INSERT INTO Client(Nom,Prenom,Adresse,Téléphone,date) VALUES(@p1,@p2,@p3,@p4,@p5)",Conn)

'Add parameters'

Save.ExecuteNonQuery()
0

Everything's alright except that u failed to use the dataadapter class found in the OleDb Class library, also, for ur database query functions to work, you have to initialize a command builder class which is also found in the class library mentioned above, initialize it with this statement - private cmbuilder as new OleDb.OleDbCommandBuilder(dataadapter[which must have been initialized]). This is how u initialize the dataadapter- private dataadapter as new OldDb.OlddbDataAdapter(query string)., use the dataadapter as a link to d database. Initialize a datatable object, then call the fill method of the dataadapter (the intellisense list will give u a hint on what to do at each point in time). Remember, the dataadapter can also update the database with new data by just a method call with the right parameters, delete data, e.t.c., forgive my typing if its inconvenient for u. (i'm using a mobile phone).

0

if these are the only fields in ur table client then y use the field name just use the parameters
one mistake is u shud use datetimepicker1.value and not text

Give a try

Try
   Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = C:\projet.mdb"
   Dim Save As OleDbCommand
   Save = New OleDbCommand("INSERT INTO Client("'+TextBox1.Text+'","'+ TextBox2.Text+'", "'+ TextBox3.Text+'", "'+TextBox4.Text+'",'"DateTimePicker1.Value+'")", ConStr)
   Dim DBReader As OleDbDataReader = Save.ExecuteReader
   DBReader.Close()
Catch ex As Exception
   Exit Sub
End Try
0

hye! since i'm a new members, can anyone help me.

what query should i used to join the table example LOGIN table with REGISTRATION table. then where should i store the query? im using vb 2010 + microsoft access 2003

here's the details about my data table.

** LOGIN : staff_id (PK), Username
REGISTER : staff_Id (PK), staff_name, Username**

0

Something like this:

Dim sqls as String = "SELECT lastname, firstname, tag" & _
     "FROM drivers, vehicles " & _
     "WHERE drivers.location = vehicles.location"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.