Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

e,@Height,@Weight,@Target)", conn)) ;
Remove the semi-colon from the end of the line - that should fix both errors.
 
Share this answer
 
Comments
DanHodgson88 1-Aug-11 4:19am    
argh! something so simple! Thanks very much! 5*
Abhinav S 1-Aug-11 4:24am    
Happens all the time. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900