database - Insert data from Datagridview to Datatable in C#? -


i capable of inserting data datagridview datatable using c#. fail update data datagridview datatable using c# windows application?

   (int = 0; <= dgvspplrfrm.rows.count-1;i++)         {             drlocal = dtlocalc.newrow();             drlocal["splr_slno"] = dgvspplrfrm.rows[i].cells[0].value;             drlocal["splr_cntctnm"] = dgvspplrfrm.rows[i].cells[1].value;             drlocal["splr_cntctdesig"] = dgvspplrfrm.rows[i].cells[2].value;             drlocal["splr_cntctmoblno"] = dgvspplrfrm.rows[i].cells[3].value;             drlocal["splr_cntctemail"] = dgvspplrfrm.rows[i].cells[4].value;             dtlocalc.rows.add(drlocal);         } 

make sure datatable contains column want copy. careful columnname of datatable datagridview. can try :

public datatable getdatatable() {     datatable dtlocalc = new datatable();     dtlocalc.columns.add("splr_slno");     dtlocalc.columns.add("splr_cntctnm");     dtlocalc.columns.add("splr_cntctdesig");     dtlocalc.columns.add("splr_cntctmoblno");     dtlocalc.columns.add("splr_cntctemail");      datarow drlocal = null;     foreach (datagridviewrow dr in dgvspplrfrm.rows)     {         drlocal = dtlocalc.newrow();         drlocal["splr_slno"] = dr.cells["splr_slno"].value;         drlocal["splr_cntctnm"] = dr.cells["splr_cntctnm"].value;         drlocal["splr_cntctdesig"] = dr.cells["splr_cntctdesig"].value;         drlocal["splr_cntctmoblno"] = dr.cells["splr_cntctmoblno"].value;         drlocal["splr_cntctemail"] = dr.cells["splr_cntctemail"].value;         dtlocalc.rows.add(drlocal);     }      return dtlocalc; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -