I have written code in C# and integrated it with SQL Server, but each time I run it I keep getting this error:
System.Data.SqlClient.SqlException: 'Incorrect syntax near ';'.'
My code is this:
private void btnsubmit_Click(object sender, EventArgs e)
{
var connectiontring =
ConfigurationManager.ConnectionStrings["connData"].ConnectionString;
string querystring = "INSERT INTO [Table] VALUES(@Name, @Gender, @Age, @Course, @Department, @Program, @Address, @PostCode, @Email;";
using (var connection = new SqlConnection(connectiontring))
{
var cmd = new SqlCommand(querystring, connection);
connection.Open();
cmd.Parameters.AddWithValue("Name", tblName.Text);
...
cmd.Parameters.AddWithValue("Email", tbllMail.Text);
cmd.ExecuteReader();
tblName.Text = "";
...
tbllMail.Text = "";
}
}
insert into [Table] (Name, Gender, Age...) VALUES (@Name, @Gender, @Age...). Also,SqlCommandis anIDisposable, and also, Can we stop using AddWithValue() already?