Member 13846612 Ответов: 4

Как избежать репликации данных, скопированных из 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

4 Ответов

Рейтинг:
2

Gerry Schmitz

Если все, что вы делаете, это "вставляете" (а не удаляете или обновляете), то вы получите "копии".


Рейтинг:
2

Member 13846612

You can update but I thought, because for some reason the datagridview shows some null fields, this can influence the results in the database.


Or what do you suggest?

Note the information shown in the datagridview is being viewed from the biometric.


Maciej Los

Это не ответ. Пожалуйста, удалите его, чтобы избежать голосования вниз. Чтобы оставить комментарий, используйте виджет "есть вопрос или комментарий".

Рейтинг:
1

Member 13846612

Many thanks sirs, I did, but was forced to create a procedures to update the registry in the database.


Рейтинг:
0