我想将datarow过滤器值插入数据集新行

时间:2012-02-29 09:34:40

标签: c# asp.net c#-4.0 datarow

我想将datarow过滤器值插入数据表新行。我正在使用带有值的数据集。我正在使用一些表达式来使用datarow.rowfilter过滤数据集行。现在datarow.row过滤器有一行。现在我想将该行插入数据表但我不能这样做..请帮我这样做..

我的部分代码在这里..

   DV = DS.DefaultView;
   DT = DS.Copy();
   DT1 = DT.Clone();

                foreach (DataRow dr in DS.Rows)
                {

                    DT1.NewRow();             
                    forward1 = Convert.ToString(dr["fldforward1"]);
                    forward2 = Convert.ToString(dr["fldforward2"]);
                    forward3 = Convert.ToString(dr["fldforward3"]);
                    forward4 = Convert.ToString(dr["fldforward4"]);
                    forward5 = Convert.ToString(dr["fldforward5"]);
                    string status = Convert.ToString(dr["fldstatus"]);
                    string date1 = Convert.ToString(dr["fldrequestdate"]);

                    if (" " == forward1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "<script language='javascript'>alert('Error for reading data...');</script>", false);
                    }
                    else if ("" == forward2)
                    {

                        DV.RowFilter = "fldforward1='" + forward1 + "' and fldstatus='Pending' and  fldrequestdate='" + date1 + "'";
                       // DT1.Rows.Add(DV); //DV.RowFilter having a row . I want to insert to datatable DT1 row 

                    }


                }

请帮我这样做....

1 个答案:

答案 0 :(得分:0)

如果您确定只有一行,那么您可以使用

DT1.ImportRow(DS.Select("fldforward1='" + forward1 + "' and fldstatus='Pending' and  fldrequestdate='" + date1 + "'")[0]);