Srm Matin

Srm Matin

  • NA
  • 38
  • 2k

Datagridview problem when form load

Apr 20 2020 11:59 PM
hi .. I Have Problem When i click save button in my winform and want save decrypted sql value into database , everything is ok but when i want add this value to datagridview row and refresh my rows Whit this value and row , DATAGRIDVIEW show other rows whit this ....EXAM : i have 3 recrord {1,2,3} , and i save one recorde {4} when i call datagridview fill in my form load an want refresh that , show {1,2,3,4}{1,2,3,4} - means duplicate row
  1. void loaddgvdata() {  
  2.  try {  
  3.   sda.SelectCommand = command;  
  4.   sda.SelectCommand.Connection = connection;  
  5.   sda.SelectCommand.CommandText = "SELECT * FROM personnal";  
  6.   sda.Fill(ds, "personnal");  
  7.   dgpersonal.DataSource = ds;  
  8.   dgpersonal.DataMember = "personnal";  
  9.   dgpersonal.SelectionMode = DataGridViewSelectionMode.FullRowSelect;  
  10.   dgpersonal.Columns[0].HeaderText = "????? ??????";  
  11.   dgpersonal.Columns[0].Frozen = true;  
  12.   dgpersonal.Columns[1].HeaderText = "???";  
  13.   dgpersonal.Columns[2].HeaderText = "???";  
  14.   dgpersonal.Columns[3].HeaderText = "???";  
  15.   dgpersonal.Columns[4].HeaderText = "???";  
  16.   dgpersonal.Columns[5].HeaderText = "???";  
  17.   dgpersonal.Columns[6].HeaderText = "???";  
  18.   dgpersonal.Columns[7].HeaderText = "???";  
  19.   dgpersonal.Columns[8].HeaderText = "???";  
  20.   dgpersonal.Columns[9].HeaderText = "???";  
  21.   dgpersonal.Columns[10].HeaderText = "???";  
  22.   dgpersonal.Columns[11].HeaderText = "???";  
  23.   connection.Open();  
  24.   dr = command.ExecuteReader();  
  25.   int rowindex = 0;  
  26.   while (dr.Read()) {  
  27.    var inputname = dr["name"].ToString();  
  28.    var passwordname = password;  
  29.    var resultname = AesCryptography.DecryptText(inputname, passwordname);  
  30.    dgpersonal.Rows[rowindex].Cells[1].Value = resultname;  
  31.    var inputlname = dr["lname"].ToString();  
  32.    var passwordlname = password;  
  33.    var resultlname = AesCryptography.DecryptText(inputlname, passwordlname);  
  34.    dgpersonal.Rows[rowindex].Cells[2].Value = resultlname;  
  35.    var inputdadname = dr["dadname"].ToString();  
  36.    var passworddadname = password;  
  37.    var resultdadname = AesCryptography.DecryptText(inputdadname, passworddadname);  
  38.    dgpersonal.Rows[rowindex].Cells[3].Value = resultdadname;  
  39.    var inputbirth = dr["birth"].ToString();  
  40.    var passwordbirth = password;  
  41.    var resultbirth = AesCryptography.DecryptText(inputbirth, passwordbirth);  
  42.    dgpersonal.Rows[rowindex].Cells[4].Value = resultbirth;  
  43.    var inputidnum = dr["idnum"].ToString();  
  44.    var passwordidnum = password;  
  45.    var resultidnum = AesCryptography.DecryptText(inputidnum, passwordidnum);  
  46.    dgpersonal.Rows[rowindex].Cells[5].Value = resultidnum;  
  47.    var inputidmeli = dr["idmeli"].ToString();  
  48.    var passwordidmeli = password;  
  49.    var resultidmeli = AesCryptography.DecryptText(inputidmeli, passwordidmeli);  
  50.    dgpersonal.Rows[rowindex].Cells[6].Value = resultidmeli;  
  51.    var inputtahsil = dr["tahsil"].ToString();  
  52.    var passwordtahsil = password;  
  53.    var resulttahsil = AesCryptography.DecryptText(inputtahsil, passwordtahsil);  
  54.    dgpersonal.Rows[rowindex].Cells[7].Value = resulttahsil;  
  55.    var inputjob = dr["job"].ToString();  
  56.    var passwordjob = password;  
  57.    var resultjob = AesCryptography.DecryptText(inputjob, passwordjob);  
  58.    dgpersonal.Rows[rowindex].Cells[8].Value = resultjob;  
  59.    var inputpay = dr["pay"].ToString();  
  60.    var passwordpay = password;  
  61.    var resultpay = AesCryptography.DecryptText(inputpay, passwordpay);  
  62.    dgpersonal.Rows[rowindex].Cells[9].Value = resultpay;  
  63.    var inputmony = dr["mony"].ToString();  
  64.    var passwordmony = password;  
  65.    var resultmony = AesCryptography.DecryptText(inputmony, passwordmony);  
  66.    dgpersonal.Rows[rowindex].Cells[10].Value = resultmony;  
  67.    var inputaddres = dr["addres"].ToString();  
  68.    var passwordaddres = password;  
  69.    var resultaddres = AesCryptography.DecryptText(inputaddres, passwordaddres);  
  70.    dgpersonal.Rows[rowindex].Cells[11].Value = resultaddres;  
  71.    rowindex++;  
  72.   }  
  73.  } catch (SqlException ex) {  
  74.   MessageBox.Show(ex.Message);  
  75.  } finally {  
  76.   connection.Close();  
  77.   dr.Close();  
  78.  }  
  79. }  
This is my code and when click save button , call loaddgvdata()

Answers (7)