Hi, I have a requirement to check if DataTable is null then copy the row to DataTable otherwise need to append the row to the DataTable.
if(dtTable ==null){
dtTable =(fromDataRow dr in dtDetails.Rowswhere dr["ID"].ToString()==Idselect dr).CopyToDataTable();}else{// Here Need to Add a new row in DataTable and append the output of
query intoDataTable ie dtTable.DataRow row = selectedTable.NewRow();
dtTable =(fromDataRow dr in dtDetails.Rowswhere dr["ID"].ToString()==Idselect dr)// Need help here} Thanks.
if (dtTable == null)
{
dtTable = (from DataRow dr in dtDetails.Rows
where dr["ID"].ToString() == Id
select dr).CopyToDataTable();
}
else
{
var result = from DataRow dr in dtDetails.Rows
where dr["ID"].ToString() == Id
select dr;
foreach (var item in result)
{
dtTable.Rows.Add(item.ItemArray);
}
}
None
0 Points
5 Posts
Append the output of query into DataTable
Dec 19, 2018 11:30 AM|dipakprodhan.kol|LINK
Hi, I have a requirement to check if DataTable is null then copy the row to DataTable otherwise need to append the row to the DataTable.
All-Star
18815 Points
3831 Posts
Re: Append the output of query into DataTable
Dec 20, 2018 07:25 AM|Nan Yu|LINK
Hi dipakprodhan.kol ,
You can refer to below code sample :
Best Regards,
Nan Yu
Member
583 Points
265 Posts
Re: Append the output of query into DataTable
Dec 28, 2018 07:26 AM|jayakumarvinayagam|LINK
Hi,
Note: if you wanna unique rows in dtTable, then compare and remove duplicate before start merge.
Thanks,