如何将值存储在一个数据表中到另一个数据表

本文关键字:数据表 一个 另一个 存储 | 更新日期: 2023-09-27 18:20:45

 try
    {
        DataTable dtdcnomissing = new DataTable();
        dtdcnomissing.Clear();
        dtdcnomissing = objRetailBAL.DCNOMissing(objRetailPL);
        DataTable dtimport = new DataTable();
        DataTable dtmissingreport = new DataTable();
        for (int i = 0; i <= dtdcnomissing.Rows.Count - 1; i++)
        {               
            dtmissingreport.Clear();
            objRetailPL.dcnoint = Convert.ToInt32(dtdcnomissing.Rows[i]["id"].ToString());
            dtmissingreport = objRetailBAL.DCNOMissingReport(objRetailPL);
            dtimport = dtmissingreport.Clone();
            foreach (DataRow dr in dtmissingreport.Rows)
            {
                dtimport.ImportRow(dr);
            }
        }
        GVDCNoMissingReport.DataSource = dtimport;
        GVDCNoMissingReport.DataBind();

    }

我想将 dtmissing 报告数据表值存储到 dtimport 数据表中...但我没有得到正确的结果...我怎么能存储这个..

如何将值存储在一个数据表中到另一个数据表

Try this below code..
try
{
DataTable dtdcnomissing = new DataTable();
dtdcnomissing.Clear();
dtdcnomissing = objRetailBAL.DCNOMissing(objRetailPL);
DataTable dtimport = new DataTable();
DataTable dtmissingreport = new DataTable();
for (int i = 0; i <= dtdcnomissing.Rows.Count - 1; i++)
{
dtmissingreport.Clear();
objRetailPL.dcnoint = Convert.ToInt32(dtdcnomissing.Rows[i]["id"].ToString());
dtmissingreport = objRetailBAL.DCNOMissingReport(objRetailPL);
if (dtimport.Rows.Count == 0)
dtimport = dtmissingreport.Clone();
foreach (DataRow dr in dtmissingreport.Rows)
{
dtimport.ImportRow(dr);
}
}
GVDCNoMissingReport.DataSource = dtimport;
GVDCNoMissingReport.DataBind();

}

尝试 copy(( 而不是 clone((

DataTable dtNew=yourOldDL.Copy();//it will copy data and structure
DataTable dtNew=yourOldDL.Clone();//it will copy structure only