Как избежать репликации данных, скопированных из datagridview в базу данных?
I have a difficulty, I have code that allows to capture all information from the datagridview and send in the database. Whenever I have execute the code it replicates in the database, and I do not know how to do it.
public void GetAllUserID() { SqlConnection con = new System.Data.SqlClient.SqlConnection(); con = new System.Data.SqlClient.SqlConnection(); //con.ConnectionString = ""; con.ConnectionString = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DBTESTE;Data Source=PD\PRIMAVERA"; con.Open(); SqlDataAdapter da = new SqlDataAdapter(); for (int i = 0; i <= dgvRecords.Rows.Count - 1; i++) { string insertData = "insert into tbAlluserid (MachineNumber, EnrollNumber, BackupNumber) values (@MachineNumber, @EnrollNumber, @BackupNumber)"; SqlCommand cmd = new SqlCommand(insertData, con); cmd.Parameters.AddWithValue("@MachineNumber", dgvRecords.Rows[i].Cells[0].Value); cmd.Parameters.AddWithValue("@EnrollNumber", dgvRecords.Rows[i].Cells[1].Value); cmd.Parameters.AddWithValue("@BackupNumber", dgvRecords.Rows[i].Cells[2].Value); da.InsertCommand = cmd; cmd.ExecuteNonQuery(); } }
Что я уже пробовал:
I tried, the method that allows deleting the table, but not the desired one