Abdu Abdul

Abdu Abdul

  • 1.2k
  • 409
  • 13.2k

Insert data serially using iteration C#

Dec 11 2021 10:11 PM

Hello good day Great minds

I have a simple problem yet complex for me. Irun this simple program which saves data into database depending on the number of times it replecate same data into database. Let i want to ave data 2x, it will save such data 2x into database, is working fine. Now the big problem is i have a database column called (order), this field store the position of data saved, let say i want to save same data twice into database, i want the first data inserted to have "First Data" in the (order) column, the second data to be inserted should have "Second Data" in the (order) column. i wish you understand to problem

int count = Convert.ToInt32(nor_combo.Text);  (Get the dropdown value)

for (int i = 0; i < count; i++) (iterate X times)
 {
   MySqlCommand in_sert = new MySqlCommand("INSERT INTO table_A (name,position,"order") VALUES(@name,@position)", connect.connect);
   in_sert.Parameters.AddWithValue("@name",textBox1.Text);
   in_sert.Parameters.AddWithValue("@position", textBox2.Text);
   in_sert.ExecuteNonQuery();
 }

Answers (3)