Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();

              }
          }


What I have tried:

I tried, the method that allows deleting the table, but not the desired one
Posted
Updated 20-Jun-18 22:24pm

If all you every do is "INSERT" (and not DELETE or UPDATE), then you will get "replicates".
 
Share this answer
 
 
Share this answer
 
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.
 
Share this answer
 
Comments
Maciej Los 19-Jun-18 3:48am    
This is not an answer. Please, delete it to avoid down-voting. To post comment, use "Have a question or comment" widget.
Many thanks sirs, I did, but was forced to create a procedures to update the registry in the database.
 
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