S
Samy K
I'm having a bit of problems entering a new row to an
access database and what I would like to know is do I have
to assign certain values in my INSERT INTO SQL statement.
I have read about the commandbuilder and it said that the
insert command is automatically generated. Below is my
code. Can someone help me out into where the syntax error
is happening:
Dim readwrite As OleDb.OleDbDataAdapter
Dim CmdBuilder As OleDb.OleDbCommandBuilder
Dim ds As DataSet = New DataSet()
Dim table As DataTable
Dim row As DataRow
'sqlstring is global variable with string "Select
* from inv_compt_invest"
readwrite = New OleDb.OleDbDataAdapter(sqlstring,
dbInventaire)
CmdBuilder = New OleDb.OleDbCommandBuilder
(readwrite)
readwrite.InsertCommand =
CmdBuilder.GetInsertCommand()
MsgBox(readwrite.InsertCommand.CommandText)
Try
readwrite.Fill(ds, "inv_compt_invest")
'output data from dataset
table = ds.Tables.Item(0)
If table.Rows.Count <> 0 Then
'Enter new records
If newdataentry = True Then
row = table.NewRow()
row("Date d'acquisition") = CDate
(TextBox2.Text)
row("Num de Compte") = CInt
(TextBox3.Text)
row("Designation de l'article") =
TextBox4.Text
row("Quantite") = CInt(TextBox5.Text)
row("Fournisseur") = TextBox6.Text
row("Num de la facture") =
TextBox7.Text
row("Marque") = TextBox8.Text
row("Localisation") = TextBox9.Text
table.Rows.Add(row)
'Update the database table
readwrite.Update
(ds, "inv_compt_invest") 'The exception gets triggered
here through debugging
newdataentry = False
Else
MsgBox("Need to enter new data to save
to Database")
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
thanks,
Sam
access database and what I would like to know is do I have
to assign certain values in my INSERT INTO SQL statement.
I have read about the commandbuilder and it said that the
insert command is automatically generated. Below is my
code. Can someone help me out into where the syntax error
is happening:
Dim readwrite As OleDb.OleDbDataAdapter
Dim CmdBuilder As OleDb.OleDbCommandBuilder
Dim ds As DataSet = New DataSet()
Dim table As DataTable
Dim row As DataRow
'sqlstring is global variable with string "Select
* from inv_compt_invest"
readwrite = New OleDb.OleDbDataAdapter(sqlstring,
dbInventaire)
CmdBuilder = New OleDb.OleDbCommandBuilder
(readwrite)
readwrite.InsertCommand =
CmdBuilder.GetInsertCommand()
MsgBox(readwrite.InsertCommand.CommandText)
Try
readwrite.Fill(ds, "inv_compt_invest")
'output data from dataset
table = ds.Tables.Item(0)
If table.Rows.Count <> 0 Then
'Enter new records
If newdataentry = True Then
row = table.NewRow()
row("Date d'acquisition") = CDate
(TextBox2.Text)
row("Num de Compte") = CInt
(TextBox3.Text)
row("Designation de l'article") =
TextBox4.Text
row("Quantite") = CInt(TextBox5.Text)
row("Fournisseur") = TextBox6.Text
row("Num de la facture") =
TextBox7.Text
row("Marque") = TextBox8.Text
row("Localisation") = TextBox9.Text
table.Rows.Add(row)
'Update the database table
readwrite.Update
(ds, "inv_compt_invest") 'The exception gets triggered
here through debugging
newdataentry = False
Else
MsgBox("Need to enter new data to save
to Database")
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
thanks,
Sam