T
Terry Burns
OK i have the following table in access.
F1 Integer
F2 String
F3 String
F4 ( Primary Key ) Autonumber
I Can get this into a table and display it on a datagrid ok. But when I try
and add a new row and update it I get the invalid INSERT. What should the
INSERT command look like and how do we get the next unique number from
access ?
Here is my code to insert
Dim DR As DataRow = tableEvents.NewRow()
Dim cmd As New OleDbCommand
cmd.CommandText = "INSERT INTO Events(Action, Comments, EventType,
PersonIndex,ID) VALUES (?, ?, ?, ?.?)"
cmd.Connection = con
cmd.Parameters.Add(New OleDbParameter("ID",
System.Data.OleDb.OleDbType.Integer, 0, "ID"))
cmd.Parameters.Add(New OleDbParameter("Action", OleDbType.VarWChar, 50,
"Action"))
cmd.Parameters.Add(New OleDbParameter("Comments", OleDbType.VarWChar, 0,
"Comments"))
cmd.Parameters.Add(New OleDbParameter("EventType", OleDbType.VarWChar, 50,
"EventType"))
cmd.Parameters.Add(New OleDbParameter("PersonIndex", OleDbType.Integer, 0,
"PersonIndex"))
Try
con.Open()
DR("PersonIndex") = dgPeople.Item(dgPeople.CurrentRowIndex, 0)
DR("EventType") = "Birthday"
DR("Comments") = ""
DR("Action") = ""
DR("ID") = 33
tableEvents.Rows.Add(DR)
daEvents.Update(tableEvents)
Catch ex As OleDbException
MessageBox.Show(ex.Message)
Catch ex As InvalidOperationException
MessageBox.Show(ex.Message)
Finally
con.Close()
End Try
F1 Integer
F2 String
F3 String
F4 ( Primary Key ) Autonumber
I Can get this into a table and display it on a datagrid ok. But when I try
and add a new row and update it I get the invalid INSERT. What should the
INSERT command look like and how do we get the next unique number from
access ?
Here is my code to insert
Dim DR As DataRow = tableEvents.NewRow()
Dim cmd As New OleDbCommand
cmd.CommandText = "INSERT INTO Events(Action, Comments, EventType,
PersonIndex,ID) VALUES (?, ?, ?, ?.?)"
cmd.Connection = con
cmd.Parameters.Add(New OleDbParameter("ID",
System.Data.OleDb.OleDbType.Integer, 0, "ID"))
cmd.Parameters.Add(New OleDbParameter("Action", OleDbType.VarWChar, 50,
"Action"))
cmd.Parameters.Add(New OleDbParameter("Comments", OleDbType.VarWChar, 0,
"Comments"))
cmd.Parameters.Add(New OleDbParameter("EventType", OleDbType.VarWChar, 50,
"EventType"))
cmd.Parameters.Add(New OleDbParameter("PersonIndex", OleDbType.Integer, 0,
"PersonIndex"))
Try
con.Open()
DR("PersonIndex") = dgPeople.Item(dgPeople.CurrentRowIndex, 0)
DR("EventType") = "Birthday"
DR("Comments") = ""
DR("Action") = ""
DR("ID") = 33
tableEvents.Rows.Add(DR)
daEvents.Update(tableEvents)
Catch ex As OleDbException
MessageBox.Show(ex.Message)
Catch ex As InvalidOperationException
MessageBox.Show(ex.Message)
Finally
con.Close()
End Try