Skip to content

C# and sql server error

Irakli Lekishvili

Asked Oct 26, 2010, 12:08 PM EDT1 answer
Share
LinkedInX
when im trying to use this code, vs shows me this error:
< Unclosed quotation mark after the character string '@bc'.
Incorrect syntax near '@bc'.>

does anybody have idea where is problem?


C#
     internal static void EditProduct(string txtBarCode, string txtArtNumber, string txtProductName, string txtPrice, string txtComment, decimal NumericUpDown1, string PriceWithOutAWD, string txtSelfPrice) 
        {
            SqlConnection con = new SqlConnection(ConnectionString);
            SqlCommand cmd = new SqlCommand("UPDATE Products SET BarCode = @BarCode, ArtNumber = @ArtNumber, ProductName = @ProductName, Price = @Price, SelfPrice = @SelfPrice, PriceWithOutAWD = @PriceWithOutAWD, UnitsInStock = @UnitsInStock, Comment = @Comment WHERE BarCode = '@bc", con);

            
            cmd.Parameters.Add(new SqlParameter("@BarCode", txtBarCode));
            cmd.Parameters.Add(new SqlParameter("@ArtNumber", txtArtNumber));
            cmd.Parameters.Add(new SqlParameter("@ProductName", txtProductName));
            cmd.Parameters.Add(new SqlParameter("@Price", txtPrice));
            cmd.Parameters.Add(new SqlParameter("@SelfPrice", txtSelfPrice));
            cmd.Parameters.Add(new SqlParameter("@PriceWithOutAWD", PriceWithOutAWD));
            cmd.Parameters.Add(new SqlParameter("@UnitsInStock", NumericUpDown1));
            cmd.Parameters.Add(new SqlParameter("@Comment", txtComment));
            cmd.Parameters.Add(new SqlParameter("@bc", txtBarCode));
            //cmd.Parameters.Add(new SqlParameter("@an", txtArtNumber));
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You're missing a single qoute in the SqlCommand cmd.
    Try this.
    SqlCommand cmd = new SqlCommand("UPDATE Products SET BarCode = @BarCode, ArtNumber = @ArtNumber, ProductName = @ProductName, Price = @Price, SelfPrice = @SelfPrice, PriceWithOutAWD = @PriceWithOutAWD, UnitsInStock = @UnitsInStock, Comment = @Comment WHERE BarCode = '@bc'   ", con);
    0