进行内部联接以获取输出:[]

时间:2019-05-31 12:43:35

标签: c# sql .net

我已经在Microsoft Sql Server中创建了数据库,我已经创建了两个表,为这些表创建了模型类,在编写代码之后,我得到了类似[]的输出。

List<Payment> p = new List<Payment>();
            DataTable dt = GetData("Select ID,CustomerCode,CustomerName,docDate, remarks, payAmount,paymentType, transferReference,bankCode, checkNumber, invoice, invoiceDate from PAYMENT_MODEL T1 INNER JOIN PAYMENTMODEL_INVOICEs T2 on T1.docEntry = T2.docEntry where T2.docEntry = '" + docEntry + "'");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataTable d = dt;
                if (!string.IsNullOrEmpty(d.ToString()))
                {
                    for (int j = 0; j < d.Rows.Count; j++)
                    {
                        Payment pm = new Payment()
                        {
                     ID = Convert.ToInt32(d.Rows[j]["ID"]),
                     CustomerCode = d.Rows[j]["CustomerCode"].ToString(),
                     CustomerName = d.Rows[j]["CustomerName"].ToString(),
                     docDate = d.Rows[j]["docDate"].ToString(),
                     remarks = d.Rows[j]["remarks"].ToString(),
                     payAmount = Convert.ToDouble(d.Rows[j]["payAmount"]),
                     paymentType = d.Rows[j]["paymentType"].ToString(),
                tranferReference = d.Rows[j]["tranferReference"].ToString(),
                bankCode = d.Rows[j]["tranferReference"].ToString(),
                  checkNumber = d.Rows[j][" checkNumber"].ToString(),

                    };
                    foreach (DataRow datarow in d.Rows)
                     {
                    pm.paymentinvoice.Add(
                         new PaymentInvoice()
                    {
                        invoice = Convert.ToInt32(datarow["invoice"]),
                        invoiceDate = datarow["invoiceDate"].ToString()
                    });
                    p.Add(pm);
                }


                }

            }
        return p;

    }

0 个答案:

没有答案