Hi there. This may seem to be an age-old problem to many of you, but I have searched almost everywhere, and haven't found a solution that worked. I have an access database on a network drive, which I am viewing on a datagridview on my form. This DB has 5 columns including the primary key, which i an autonumber column named ID. The other 4 are Number(string), Name(String), User(String) and Datetime(Date). I am getting values on the form to be inserted into the DB, but it does not seem to work. When I use this:
cmd = New OleDbCommand("insert into Spareparts(Number, Name, User, Datetime) values ('" & projectListBox.SelectedItem.ToString.Substring(projectListBox.SelectedItem.ToString.Length - 3, 3) & "-" & numberTextbox.Text & "-" & revisionTextbox.Text & "','" & nameTextbox.Text & "','" & userTextbox.Text & "'," & Today.Date & ")", conn)
It tells me 'syntax error in INSERT INTO statement'. But when I exclude the column names:
cmd = New OleDbCommand("insert into Spareparts values ('" & projectListBox.SelectedItem.ToString.Substring(projectListBox.SelectedItem.ToString.Length - 3, 3) & "-" & numberTextbox.Text & "-" & revisionTextbox.Text & "','" & nameTextbox.Text & "','" & userTextbox.Text & "'," & Today.Date & ")", conn)
It tells me 'Number of query values and destination fields are not the same'.
Although, it DOES work when I specify a value for the ID column. I don't want to do that (obviously, that's why I made that field autonumber). Does anyone know why this is happening?
cmd = New OleDbCommand("insert into Spareparts(Number, Name, User, Datetime) values ('" & projectListBox.SelectedItem.ToString.Substring(projectListBox.SelectedItem.ToString.Length - 3, 3) & "-" & numberTextbox.Text & "-" & revisionTextbox.Text & "','" & nameTextbox.Text & "','" & userTextbox.Text & "'," & Today.Date & ")", conn)
It tells me 'syntax error in INSERT INTO statement'. But when I exclude the column names:
cmd = New OleDbCommand("insert into Spareparts values ('" & projectListBox.SelectedItem.ToString.Substring(projectListBox.SelectedItem.ToString.Length - 3, 3) & "-" & numberTextbox.Text & "-" & revisionTextbox.Text & "','" & nameTextbox.Text & "','" & userTextbox.Text & "'," & Today.Date & ")", conn)
It tells me 'Number of query values and destination fields are not the same'.
Although, it DOES work when I specify a value for the ID column. I don't want to do that (obviously, that's why I made that field autonumber). Does anyone know why this is happening?