LINQ使用C#中的Foreach字符串数组记录到Datagrid

时间:2013-06-21 07:29:07

标签: c# arrays linq datagridview

private void getPOP30300(string rr) 
{

    try
    {
        DBSFCDataContext SFC = new DBSFCDataContext();
        var query = (from i in SFC.POP30300s 
                     where i.POPRCTNM == rr 
                     select new { RRno = i.POPRCTNM, Rdate = i.receiptdate, 
                       GLSPOST = i.GLPOSTDT, VENDID = i.VENDORID, 
                       VENDNAME = i.VENDNAME, SUBT = i.SUBTOTAL, PYMT = i.PYMTRMID,
                       Ddate = i.DUEDATE, PSEDDTT = i.POSTEDDT, PTDURID = i.PTDUSRID,
                       USER2 = i.USER2ENT, CREATDDT = i.CREATDDT, MODIFDT = i.MODIFDT,
                       TRXSORCE = i.TRXSORCE, ORSUBTOT = i.ORSUBTOT, 
                       DEXROWID = i.DEX_ROW_ID, REMARKS = i.REMARKS, 
                       TRCKSCALRECIPNO = i.TRUCK_SCALERECEIPTNO, TRCKFEE = i.TRUCKFEE,
                       UNLFEE = i.UNLOADFEE, PRNTCOST = i.IsPrintCost, 
                       TRCKNO = i.TRUCKNO, QTYSHIPBAGS = i.Qtyshippedbags, GW = i.GW,
                       TAREW = i.TAREW, NETWT = i.NETWT, PKGWT = i.PKGWT, 
                       PLATENO = i.PLATENO, VPNUM = i.VPNum, VPDATE = i.VPDate,
                       AMNTNWORDS = i.AmountInWords, VPRMKS = i.REMARKS, 
                       VPPOST = i.VPPost, VPEXPRT = i.VPExport });

        foreach (var r in query)
        {

            //DGVpop30300.DataSource = r;

            string[] row = { r.RRno.Trim(), r.Rdate.ToString(), r.GLSPOST.ToString(),
                             r.VENDID.ToString(), r.VENDNAME.Trim(),
                             r.SUBT.ToString(), r.PYMT.ToString(), r.Ddate.ToString(),
                             r.PSEDDTT.ToString(), r.PTDURID.Trim(), r.USER2.Trim(), 
                             r.CREATDDT.ToString(), r.MODIFDT.ToString(),
                             r.TRXSORCE.ToString(), r.ORSUBTOT.ToString(),
                             r.DEXROWID.ToString(), r.REMARKS.Trim(), 
                             r.TRCKSCALRECIPNO.ToString(), r.TRCKFEE.ToString(),
                             r.UNLFEE.ToString(), r.PRNTCOST.ToString(),
                             r.TRCKNO.ToString(), r.QTYSHIPBAGS.ToString(),
                             r.GW.ToString(), r.TAREW.ToString(), r.NETWT.ToString(), 
                             r.PKGWT.ToString(), string.Format("{0:###-###0}", r.PLATENO), 
                             string.Format("{0:##-####0}", r.VPNUM),
                             r.VPDATE.ToString(), string.Format("{0:###,###.##0}", r.AMNTNWORDS), 
                             r.VPRMKS.ToString(), r.VPPOST.ToString(),
                             r.VPEXPRT.ToString() };

            { DGVpop30300.Rows.Add(row); }
        }
    }
    catch (Exception ex) 
    {
        MessageBox.Show(ex.Message.ToString());
    }
}

private void getPOP30310(string rr) 
{

    try
    {
        DBSFCDataContext SFC = new DBSFCDataContext();

        var query = (from i in SFC.POP30310s 
                     where i.POPRCTNM == rr 
                     select new { 
                       RRno = i.POPRCTNM, RCPTLNNM = i.RCPTLNNM, POno = i.PONUMBER,
                       ITEMno = i.ITEMNMBR, ITEMdesc = i.ITEMDESC, 
                       VNDITNUM = i.VNDITNUM, VNDITDSC = i.VNDITDSC, 
                       UMQTYINB = i.UMQTYINB, ACTLSHIP = i.ACTLSHIP, UOFM = i.UOFM,
                       UNITCST = i.UNITCOST, EXTDCST = i.EXTDCOST, 
                       LOCNCODE = i.LOCNCODE, TRXSRCE = i.TRXSORCE, 
                       JOBNUMBR = i.JOBNUMBR, COSTCODE = i.COSTCODE, 
                       COSTTYPE = i.COSTTYPE, ORNUNTCST = i.ORUNTCST, 
                       OREXTCST = i.OREXTCST, ODECPLCU = i.ODECPLCU, 
                       BOLPRONUM = i.BOLPRONUMBER, ITEMrr = i.ITEMRR, 
                       DESC = i.DESCRIPTIONRR, PYMTRMID = i.PymtrMID, 
                       WHSArea = i.WHSArea, ISCHANGE = i.IsChangeExtendedCost });

        foreach (var r in query)
        {
            string[] row = { r.RRno.Trim() };
            { DGVpop30310.Rows.Add(row); }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message.ToString());
    }
}

以上是我所做的代码..现在第一个功能完美但第二个POP30310 ..不显示任何我不知道为什么?请帮助..它们看起来完全一样,我注释掉第一个功能只是为了检查它是否在第二个工作但仍然没有显示任何试图显示的数据......

0 个答案:

没有答案