❔ inserting data from visual studio to mysql databases

namespace hw6q1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string x = "server =localhost; database =registration; uid =root; password =123456"; MySqlConnection conn = new MySqlConnection(x); string y = "INSERT INTO registration(Firstname,Lastname,Address,City,State,Postcode,country,Email) VALUES(" + textBox1.Text + ",'" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "')"; try { conn.Open(); MySqlCommand command = new MySqlCommand(y, conn); int z = Convert.ToInt32(command.ExecuteNonQuery()); command.Dispose(); conn.Close(); } catch (MySqlException ex) { MessageBox.Show(ex.Message); } } } } cant show the result no matter how i try
5 Replies
Anton
Anton2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Anton
Anton2y ago
you shouldn't be escaping the arguments manually like that, use parameters
Anton
Anton2y ago
GitHub
uni_sql/AlterUserOrRole.cs at master · AntonC9018/uni_sql
SQL queries, database designs, management and security tasks - uni_sql/AlterUserOrRole.cs at master · AntonC9018/uni_sql
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.