Okay this problem of mine is a little bit tricky for the past months now. SUMMARY: When I only have 5 columns in my Access Database my code successfully inserts the new row. But when I add another column in my access database (that will be 6 columns now) I encounter
Syntax Error INSERT INTO Statement
Code:
Dim cb As New OleDb.OleDbCommandBuilder(SYSTEM_MainClient.dbda)
Dim dsNewRow As DataRow
dsNewRow = SYSTEM_MainClient.DataSet.Tables("Database").NewRow()
dsNewRow.Item("First_Name") = TXT_FirstName.Text
dsNewRow.Item("Last_Name") = TXT_Surname.Text
dsNewRow.Item("StudentID") = CInt(TXT_StudentID.Text)
dsNewRow.Item("Middle_Name") = TXT_MiddleName.Text
dsNewRow.Item("College") = TXT_College.Text
SYSTEM_MainClient.DataSet.Tables("Database").Rows.Add(dsNewRow)
SYSTEM_MainClient.dbda.Update(SYSTEM_MainClient.DataSet, "Database")
MsgBox("New Record added to the Database")
My database cColumns:
"StudentID" (primary key),
"First_Name", "Last_Name", "Middle_Name"
"College"
RESULT: This will work okay, and new record is added into the database.
Because there is only 5 columns.
BUT IF I EXCEED:
Code:
Dim cb As New OleDb.OleDbCommandBuilder(SYSTEM_MainClient.dbda)
Dim dsNewRow As DataRow
dsNewRow = SYSTEM_MainClient.DataSet.Tables("Database").NewRow()
dsNewRow.Item("First_Name") = TXT_FirstName.Text
dsNewRow.Item("Last_Name") = TXT_Surname.Text
dsNewRow.Item("StudentID") = CInt(TXT_StudentID.Text)
dsNewRow.Item("Middle_Name") = TXT_MiddleName.Text
dsNewRow.Item("College") = TXT_College.Text
dsNewRow.Item("Section") = TXT_Section.Text 'I added a section insert
SYSTEM_MainClient.DataSet.Tables("Database").Rows.Add(dsNewRow)
SYSTEM_MainClient.dbda.Update(SYSTEM_MainClient.DataSet, "Database")
MsgBox("New Record added to the Database")
My database columns:
"StudentID" (primary key)
"First_Name", "Last_Name", "Middle_Name"
"College", "Section".
It will return an error
Syntax Error INSERT INTO Statement
It's like it can only insert not more than 5 column values, I think the problem is access not VB itself.
I hope you understand my problem, please help me It's my problem for months now, I searched the forums and Googled it, still can't find the answer.
Thank you so much!
update commandof thedbdacan you show it? if problem be with it we will fix itsectionis an access reserved word.support2.microsoft.com/default.aspx?scid=kb;en-us;286335. Try changing it to something else