I don't know whether this question fits here or not, but if it doesn't let me know. I'm a much much beginner in programming, and I've started it in vb.net for a project I've to do for my college work.

To add the data of a user in the database through a form in visual studio, when I fill the values for the fields in the user's form, I'm having a "Syntax Error in INSERT INTO statement" error for adding the entries in the access database when I click the button.

After looking at a solution on this website (https://www.daniweb.com/programming/software-development/threads/489939/inserting-data-into-two-separate-tables-in-an-access-database#), I change the code to this one below:

usersform_programchanged_screenshot.png

But it still doesn't work and gives the error:

Untitled.png

In the database, the UsersTable has a UserID column with datatype 'AutoNumber' and all the other columns mentioned in the sql query code above, and the table is completely empty.
The LoginTable has the same UserID column with datatype 'Number'and the username and password columns. This table is also completely empty.
The UsersTable is linked in relationships with LoginTable through the UserID, Username and Password columns.

How can I add the data of a user in both the tables at one go?

Please help me as soon as possible!

Recommended Answers

All 8 Replies

I'm not entirely sure that your last error message is something caused by the shown code. What line is causing the exception exactly?

I don't know what line is causing that exception.
I fill the fields of the user form, and click the Register button. But it doesn't add the data into the database and shows the error I posted above in the image.
Please, can you understand what is wrong with the code above?

What happens if you set a breakpoint at the start of that method and step through your code?

I'm not sure I understand what you mean.
Would it enable me to add the data into the two tables UsersTable and LoginTable?
Could you please show me how?
(Note: I am too much of a beginner)

For future reference, please post text intead of a lo-res, blurry, hard to read image of text. Some of us are dinosaurs with somewhat less than 2020 vision.

First of all, I agree with Reverend Jim - please post your code.
Secondly, look carefully at the example you mention. I think you will find that you are not really following it. Notice the
& "', '" &
that separates the data items.
I think you are possibly trying to get more out of String.Format than it has to offer.

More values than columns!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.