I've attempting to insert data into my localhost database (xampp phpmyadmin), but I keep receiving this error. I tried looking up the exception but have not been able to find any answers.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ProductMaintenance
{
public partial class Form1 : Form
{
SqlConnection connection = new SqlConnection("server=localhost;user id=root123;database=test;allowuservariables=True;persistsecurityinfo=True");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
connection.Open();
SqlCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into [mytable] (Name,Surname,Address) values (' "+ textBox1.Text + " ', '" + textBox2.Text + " ', ' " + textBox3 + "')";
cmd.ExecuteNonQuery();
connection.Close();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}