新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
探尋linq多條件查詢
linq多條件查詢?nèi)绾螌?shí)現(xiàn)呢,以及實(shí)現(xiàn)過(guò)程中遇到的問(wèn)題如何解決呢?本文就來(lái)給你一個(gè)答案。

創(chuàng)新互聯(lián)主營(yíng)松桃網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app開(kāi)發(fā),松桃h5小程序開(kāi)發(fā)搭建,松桃網(wǎng)站營(yíng)銷(xiāo)推廣歡迎松桃等地區(qū)企業(yè)咨詢
linq多條件查詢,當(dāng)條件為NUll時(shí)不做查詢,只有條件有值時(shí)才作為查詢條件查詢。下面我們就給大家進(jìn)行一下分析。
時(shí)間 AddTime
名稱(chēng) Name
- //添加時(shí)間開(kāi)始
- string strAddTimeStart = txtAddTimeStart.Text;
- DateTime AddTimeStart = SqlDateTime.MinValue.Value;
- if (!string.IsNullOrEmpty(strAddTimeStart))
- {
- AddTimeStart = Convert.ToDateTime(strAddTimeStart );
- }
- //添加時(shí)間結(jié)束
- string strAddTimeEnd = txtAddTimeEnd.Text;
- DateTime AddTimeEnd = SqlDateTime.MaxValue.Value;
- if (!string.IsNullOrEmpty(strAddTimeEnd))
- {
- AddTimeEnd = Convert.ToDateTime(strAddTimeEnd);
- }
- var resultsql = from w in students
- where
- (!string.IsNullOrEmpty(strAddTimeStart) ? AddTimeStart >=
- w.addTime : true) &&
- (!string.IsNullOrEmpty(strAddTimeEnd) ? AddTimeEnd >=
- w.addTime : true) &&
- (!string.IsNullOrEmpty(OCState) ? w.Name.Equals(Name) : true)
- select new
- {w.name,
- w.sex
- };
linq多條件查詢需要注意的是,下面這樣是不對(duì)的,會(huì)報(bào)無(wú)法識(shí)別的DateTime。
- (!string.IsNullOrEmpty(strAddTimeStart) ?
- Convert.ToDateTime(AddTimeStart) >= w.addTime : true)
所以時(shí)間必須在外邊轉(zhuǎn)換。
以上就是對(duì)linq多條件查詢的簡(jiǎn)單介紹。
【編輯推薦】
- LINQ動(dòng)態(tài)查詢的實(shí)現(xiàn)淺析
- LINQ TO SQL動(dòng)態(tài)修改表名稱(chēng)的實(shí)現(xiàn)淺析
- LINQ To SQL的一點(diǎn)討論
- 淺析LINQ事務(wù)處理的實(shí)現(xiàn)
- 淺析DataSet和DataTable
分享題目:探尋linq多條件查詢
網(wǎng)站URL:http://www.5511xx.com/article/dphisde.html


咨詢
建站咨詢
