Friday, 27 September 2013

sorucetable.Select providing 2 coulms data does not work

sorucetable.Select providing 2 coulms data does not work

I created a method that takes a source data table, destination data table
, column name and value. the copies only data rows that match the value of
the column. this wroks but now I need to give 2 column names and 2 values
but It is not working following is the code I have so far.
public void SortDataByType(DataTable SourceTable, DataTable
ReturnedResult, String Custnum, string Columnname)
{
var detailedRows = SourceTable.Select(String.Format(Columnname +
"={0}", Custnum));
foreach (var detailRow in detailedRows)
{
ReturnedResult.Rows.Add(detailRow.ItemArray);
}
}
Above works fine.
below does not work.
public void SortDataByType(DataTable SourceTable, DataTable
ReturnedResult, String Custnum, String District , string
Columnname,string Columnname2)
{
var detailedRows = SourceTable.Select(String.Format(Columnname +
"={0}" , Columnname2+"{1}",Custnum,District));
foreach (var detailRow in detailedRows)
{
ReturnedResult.Rows.Add(detailRow.ItemArray);
}
}

No comments:

Post a Comment