如何转换SQL Querry [英] How to convert SQL Querry
问题描述
如何转换此查询
How to convert this query
"SELECT NamaBulan from Parameter where Bulan= $bulan1"
如果我有
if i have
var bulan1= DateTime.Now.Month;
i尝试过这样但是仍然不能正常工作。
i have try like this but still not work.
if (ModelState.IsValid)
{ var bulan1= DateTime.Now.Month.ToString();
var bulan2= from z in p.NamaBulan where bulan1==p.Bulan
select z;
search.Day = bulan2.ToString();
谢谢!
Thanks!
推荐答案
bulan1
bulan1"
如果我有
if i have
var bulan1= DateTime.Now.Month;
i尝试这样但仍然无效。
i have try like this but still not work.
if (ModelState.IsValid)
{ var bulan1= DateTime.Now.Month.ToString();
var bulan2= from z in p.NamaBulan where bulan1==p.Bulan
select z;
search.Day = bulan2.ToString();
谢谢!
Thanks!
我接受它,p是你的收藏哟你查询。如果是这种情况,查询将迭代p中的项目,您将使用项目的各个属性。如下所示:
I take it, p is your collection you query. If that is the case the query would iterate through the items in p and you would use the individual properties of the items. Something like the following:
var queryresult = from item in p
where item.bulan == bulan1
select item.NamaBulan;
根据条件,查询可以返回多行,以便您可以遍历它们或如果您只需要第一个,如果有可能没有返回任何项目,您可以使用First或FirstOrDefault。类似
Depending on the conditions the query could return several rows so you could loop through them or if you just need the first, you can take the First or FirstOrDefault if there is a possibility that no items are returned. Something like
var bulan2 = queryresult.FirstOrDefault();
作为旁注,看起来您已将部分日期存储在单独的字段中。如果这是真的,我建议使用单个字段作为日期,并在需要部分日期时使用日期函数。
As a side note it looks like you have stored parts of the dates in separate fields. If this is true, I would suggest using a single field for a date and using date functions if parts of the dates are needed.
这篇关于如何转换SQL Querry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!