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

时间:2014-09-04 07:11:57

标签: c# asp.net

 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();


    }

我想将dtmissingreport数据表值存储到dtimport datatable中...但是我没有得到正确的结果......我怎样才能存储它..

2 个答案:

答案 0 :(得分:1)

尝试复制()而不是克隆()

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

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

答案 1 :(得分:1)

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();


}