Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
125 views
in Technique[技术] by (71.8m points)

c# - Why am I getting an SQL Syntax error when trying to insert data into a row?

I am getting a strange MYSQL error when trying to write a row to a database - every solution I have found concerning the topic hasn't been helpful. The query being passed is this:

"INSERT INTO StaffData (StaffID,Sort,Name,Department,Occupation,Roles,Phone,Email,Notes,Password) VALUES (@StaffID,@Sort,@Name,@Department,@Occupation,@Roles,@Phone,@Email,@Notes,@Password) ON DUPLICATE KEY UPDATE"

And the return value is:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"

The strange part to me is that it doesn't say where the error in syntax is, and I'm not sure why. Every other instance of this error I have found at least provides that.

Any help would be appreciated - thanks in advance!

question from:https://stackoverflow.com/questions/65878361/why-am-i-getting-an-sql-syntax-error-when-trying-to-insert-data-into-a-row

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your error is in the syntax for "ON DUPLICATE KEY UPDATE".

You can't end a query there, MYSQL wants you to specify exactly which fields should be updated and how. The docs for how to do that can be found here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...