Skip to content
Advertisement

How to Insert C# values to MySql?

I want to insert C# winform values to Mysql

there are 3 columns

name,id are TextBox text and gender is ComboBox value

but there is error and error messsage said: MySql.Data.MySqlClient.MySqlException: ‘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′

what code should i fix?

Advertisement

Answer

You’re missing a single quote in the connecting string literal between name3.Text and id3.Text and again between id3.Text and gender3.SelectedValue

But it shouldn’t matter. If you’re concatenating user-supplied strings like this it’s only a matter of time until your system is breached. There’s a better way that avoids this risk, makes it easier to get your SQL statements correct, and runs faster.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement