Click here to Skip to main content
16,004,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Guys, my problem is when i insert value database so extra value add in database for example i insert 2 values in db but value insert 3 but sometimes it's insert perfectly but sometimes i am facing extra value issue.
please guys see my code and give me solution of this issue please.

Thank you

What I have tried:

C#
OleDbCommand command = new OleDbCommand();
                command.Connection = connection;
                command.CommandText = @"INSERT INTO Total ([Column1], [Column2], [Column3], [Date], [Receipt No], [Delivery Person], [Report], [Flavours], [Return])
VALUES (@Column1, @Column2, @Column3, @Date, @ReceiptNo, @DeliveryPerson, @Report, @Flavours, @Return)";
                connection.Open();
                 for (int j = 0; j < dataGridView1.Rows.Count ; j++)
    {
        var row = dataGridView1.Rows[j];
        if (row.IsNewRow) continue;
        command.Parameters.Clear();
        command.Parameters.AddWithValue("@Column1", row.Cells[0].Value);
        command.Parameters.AddWithValue("@Column2", row.Cells[1].Value);
        command.Parameters.AddWithValue("@Column3", row.Cells[2].Value);
        command.Parameters.AddWithValue("@Date", row.Cells[4].Value);
        command.Parameters.AddWithValue("@ReceiptNo", label2.Text);
        command.Parameters.AddWithValue("@DeliveryPerson", "---");
        command.Parameters.AddWithValue("@Report", row.Cells[0].Value);
        command.Parameters.AddWithValue("@Flavours", row.Cells[3].Value);
        command.Parameters.AddWithValue("@Return", textBox66.Text);
        command.ExecuteNonQuery();
    } connection.Close();
                    MessageBox.Show("Inserted Sucessfully", "Database", MessageBoxButtons.OK, MessageBoxIcon.Information);
Posted
Updated 17-Nov-16 6:18am
Comments
ZurdoDev 17-Nov-16 12:03pm    
Which column? Just debug your code.
Member 9983063 17-Nov-16 12:38pm    
Debug???
[no name] 17-Nov-16 13:07pm    
How is that even a question? Yes, debug your code. It's a valuable technique by which many people find and fix their own problems.

1 solution

how does it insert extra values??? Try adding break points if you're using VS to know when it does that and post a feedback. and if not VS, debug and post the feedback
 
Share this answer
 
Comments
Richard MacCutchan 17-Nov-16 12:34pm    
This should be a comment, not a Solution.
Ayodeji Oluwatomiwo 18-Nov-16 1:56am    
my bad
Member 9983063 17-Nov-16 12:38pm    
how can i add break point bcz some times it's insert values acccurate value in db but some times it's show's extra values
Ayodeji Oluwatomiwo 18-Nov-16 4:12am    
In your VS in your code behind, you'll see the numbering if enabled. To the left of the numbering, you'll see a plain horizontal space beside the numbering. just click and it will add a red dot. click the lines where the insertion is performed and the loop in particular

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