Anisuzzaman Sumon
Вот вам готовый суп.просто используйте и не стесняйтесь, если у вас есть какие-либо вопросы
class Program
{
static DataTable dtCustomer = new DataTable();
static DataTable dtPaymentInfo = new DataTable();
static DataTable dtResults = new DataTable();
static void Main(string[] args)
{
FillDataTables();
var t = from paymentinfo in dtPaymentInfo.AsEnumerable()
join customer in dtCustomer.AsEnumerable()
on paymentinfo.Field<int>("PaymentId") equals customer.Field<int>("PaymentId")
select new { BankRef = paymentinfo.Field<string>("BankRef") , BankName = paymentinfo.Field<string>("BankName"), CustomerName = customer.Field<string>("CustomerName"), PaymentId = paymentinfo.Field<int>("PaymentId") };
dtResults.Columns.Add("BankRef", typeof(string));
dtResults.Columns.Add("BankName", typeof(string));
dtResults.Columns.Add("CustomerName", typeof(string));
dtResults.Columns.Add("PaymentId", typeof(int));
foreach (var r in t)
{
dtResults.Rows.Add(r.BankRef,r.BankName,r.CustomerName,r.PaymentId);
}
string html = ConvertDataTableToHTML(dtResults);
}
public static string ConvertDataTableToHTML(DataTable dt)
{
string html = "<table border="\"1\"">";
//add header row
html += "<tr>";
for (int i = 0; i < dt.Columns.Count; i++)
html += "<td>" + dt.Columns[i].ColumnName + "</td>";
html += "</tr>";
//add rows
for (int i = 0; i < dt.Rows.Count; i++)
{
html += "<tr>";
for (int j = 0; j < dt.Columns.Count; j++)
html += "<td>" + dt.Rows[i][j].ToString() + "</td>";
html += "</tr>";
}
html += "</table>";
return html;
}
static void FillDataTables()
{
//To fill data with your sample values for testing purpose
//SL.No CutomerId CustomerName PaymentId
dtCustomer.Columns.Add("SL.No", typeof(int));
dtCustomer.Columns.Add("CutomerId", typeof(int));
dtCustomer.Columns.Add("CustomerName", typeof(string));
dtCustomer.Columns.Add("PaymentId", typeof(int));
dtCustomer.Rows.Add(1, 12345, "ABC", 99999);
dtCustomer.Rows.Add(2, 23456, "FGH", 88888);
dtCustomer.Rows.Add(3, 54321, "MNB", 77777);
//BankRef BankName PaymentId Address City
dtPaymentInfo.Columns.Add("BankRef",typeof(string));
dtPaymentInfo.Columns.Add("BankName", typeof(string));
dtPaymentInfo.Columns.Add("PaymentId", typeof(int));
dtPaymentInfo.Columns.Add("Address", typeof(string));
dtPaymentInfo.Columns.Add("City", typeof(string));
dtPaymentInfo.Rows.Add("ref12", "HSBC", 99999, "Street11", "NY");
dtPaymentInfo.Rows.Add("ref13", "HSBC", 88888, "Street11", "NY");
}
}
</int></string></string></string></int></int>