鍍金池/ 問(wèn)答/C#  數(shù)據(jù)庫(kù)  HTML/ Linq過(guò)濾后為啥沒(méi)有數(shù)據(jù)?

Linq過(guò)濾后為啥沒(méi)有數(shù)據(jù)?

是這樣的,我剛接觸這項(xiàng)目,然后對(duì)Linq也不熟悉,項(xiàng)目里面在選擇日歷控件的日期后,篩選沒(méi)有數(shù)據(jù),只有日期這個(gè)字段是沒(méi)有篩選效果的,其他字段都可以,斷點(diǎn)看了一下,在經(jīng)過(guò)Contains的方法后,就沒(méi)有數(shù)據(jù)了,我斷點(diǎn)取了Contains里面的條件,去數(shù)據(jù)庫(kù)查詢,是可以篩選的,代碼如下:

private static EnumerableRowCollection<DataRow> NewMethod(string seacher, int ttt, string[] newtablename, List<string[]> lstmsg, DataTable ddt, EnumerableRowCollection<DataRow> objmm)
        {
            if (!string.IsNullOrEmpty(seacher) && seacher != "{")
            {
                object jsonobj = JsonConvert.DeserializeObject(seacher);
                JContainer ja = (JContainer)jsonobj;
                JToken jjjj = newtablename[ttt].Equals("tbMygrid") ? ja["tbMygrid"] : ja["tb_" + newtablename[ttt]];
                if (jjjj != null)
                {
                    object objjjj = JsonConvert.DeserializeObject(jjjj.ToString());
                    JArray jaa = (JArray)objjjj;
                    JToken[] j = jaa.AsEnumerable().First().ToArray();
                    foreach (var jitem in j)
                    {
                        string[] aa = jitem.ToString().Split(':');
                        if (aa.Length == 2)
                        {
                            string field = aa[0].Replace("\"", "[|++|]").Replace("[|++|]", "").Replace("\"", "[|++|]").Replace("[|++|]", "");
                            string fieldValue = aa[1].Replace("\"", "[|++|]").Replace("[|++|]", "").Replace("\"", "[|++|]").Replace("[|++|]", "");
                            string[] msgobj = new string[] { field.Trim(), fieldValue.Trim() };
                            lstmsg.Add(msgobj);
                            if (ddt.Columns.Contains(field.Trim())) objmm = objmm.Where(m => (Convert.IsDBNull(m[field]) ? "" : m[field].ToString().Trim().Replace("/", "-")).Contains(fieldValue.Trim()));
                        }
                    }
                }

            }
            return objmm;
        }

這是篩選的方法,最后會(huì)返回datarow,然后有下面的代碼引用:

//查詢顯示數(shù)據(jù)表
                    sql = string.Format("Select a.*,ISNULL(b.english,a.fieldcaption) AS english from pps_opmasterlist1detail  A LEFT JOIN  xt_foreign b ON b.chinese=a.fieldcaption where  a.opeid ='{0}' and  a.autoid ={1}  ORDER BY cxcol DESC,cxid ASC ", opeid, item["autoid"]);
                    sql +=Environment.NewLine+ querysql;
                    DataSet dtAll = LfemporderManager.ExecuteDataset(sql);
                    //獲取主表顯示數(shù)據(jù)
                    #region "獲取主表顯示數(shù)據(jù)"
                    DataTable dtDetail = dtAll.Tables[0];
                    DataTable dtMain = dtAll.Tables[1];
                    var objmm = dtMain.AsEnumerable();
                    List<string[]> lstmsg = new List<string[]>();
                    objmm = NewMethod(another, 0, new string[] { "tbMygrid" }, lstmsg, dtMain, objmm);
                    DataTable newdate = new DataTable();
                    if (objmm.Count() > 0) newdate = objmm.CopyToDataTable();
                    int total = objmm.Count();

newdate這個(gè)變量最后會(huì)沒(méi)有數(shù)據(jù),是空的,如果我過(guò)濾其他字段,就不會(huì)沒(méi)有數(shù)據(jù)。
數(shù)據(jù)庫(kù)的ddate字段數(shù)據(jù)如下圖片描述

我實(shí)在是不知道怎么找問(wèn)題了,請(qǐng)教一下各位如何解決?

回答
編輯回答
無(wú)標(biāo)題

在Contains前面輸出

Console.WriteLine(string.join(" ", dt.Columns))
Console.WriteLine(field.Trim())
2018年8月13日 20:16