Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
This code is not only edits cells value its edits and duplicate also
I cannot find problem please help me

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 AND ArtNumber = @an ", 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();
           }
       }
Posted
Updated 26-Oct-10 11:32am
v3
Comments
DaveAuld 26-Oct-10 17:07pm    
What do you mean it edits and duplicates? are you saying it creates a copy of the row for the one you are just editing?
Dalek Dave 26-Oct-10 17:33pm    
Edited for Readability.
Henry Minute 26-Oct-10 18:39pm    
Are you sure that this method is the one responsible for the duplication? I can see no reason that it would. Is there any chance there is a trigger on the products table that might do it, or another method in your code that inserts?

1 solution

Does barcode & artnumber collectively make the record unique?
Or duplicates too can have same values for it?

Based on your query, only reason why an edit of a given record can update a duplicate one is when you have same 'barcode + artnumber' combination for them as original has.
 
Share this answer
 

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