Hi, I have wrote this small piece of code and for some reason I have 2 errors and I can't see wh. the code is:
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
SqlConnection conn = new SqlConnection(Calorie_Counter_UK.Properties.Settings.Default.Calorie_CounterConnectionString);
conn.Open();
try
{
using (SqlCommand command = new SqlCommand("INSERT INTO User VALUES (@Name,@Age,@Height,@Weight,@Target)", conn)) ;
{
command.Parameters.Add(new SqlParameter("Name", txtName.Text));
command.Parameters.Add(new SqlParameter("Age", txtName.Text));
command.Parameters.Add(new SqlParameter("Height", txtName.Text));
command.Parameters.Add(new SqlParameter("Weight", txtName.Text));
command.Parameters.Add(new SqlParameter("target", txtName.Text));
Command.ExecuteNonQuery();
}
}
catch
{
MessageBox.Show("Could not Insert");
}
}
The errors are:
1. On the end of my using statement it is green underlined saying "possible mistaken empty statement" which quite obviously it is not empty.
2. command.parameters..... "The name 'command' does not exist in the current context" in my eyes it deffinetly does exist but doesn't seem to like it!
If anyone could shed some light on these 2 errors I would be grateful!
Thank you in advance.
Dan