📜  如何在c#代码示例中将datagridview导入数据表

📅  最后修改于: 2022-03-11 14:48:46.935000             🧑  作者: Mango

代码示例1
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;
}