Here is a little tutorial.

Imports System.Data.OleDb

First setup your Database connection.
Put the next bit of code in your Form's Public class

Dim dbInsert As New OleDb.OleDbCommand
Dim dbConnect As New OleDb.OleDbConnection

Put the next bit of code in your Form Load Private Sub

  dbConnect.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Database\Main.mdb"
Catch ex As Exception
End Try

Lets say you have 3 text boxes txtName, txtSurname & txtNumber and you want to update the database with the data in the boxes, put the following code in the update button click event Private Sub.

*NOTE: col_Name, col_Surname, col_Number are your column names in your database.

dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "col_Name"
dbInsert.Parameters.Item("col_Name").Value = txtName.Text
dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "col_Surname"
dbInsert.Parameters.Item("col_Surname").Value = txtSurname.Text
dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "col_Number"
dbInsert.Parameters.Item("col_Number").Value = txtNumber.Text

*NOTE: Table_Person is your table in the database.

dbInsert.CommandText = "INSERT INTO Table_Person VALUES (txtName.Text, txtSurname.Text, txtNumber.Text);"
dbInsert.CommandType = CommandType.Text
dbInsert.Connection = dbConnect

-Animal Mother

Edited 6 Years Ago by Animal Mother: n/a

This article has been dead for over six months. Start a new discussion instead.