注册 登录
编程论坛 ASP.NET技术论坛

同年同月同日怎么实现?

meteor86 发布于 2008-04-14 19:02, 741 次点击
我用3个DropDownList分别控制年月日,用怎样的语句查询数据库里与所选日期相同的日期的人呢?

select * from 表 where........

???????不知道了,各位帮忙啊
9 回复
#2
hebingbing2008-04-14 19:16
select * from biao where datetime='convert.todatetime("+dropdownlist1.selectedvalue.tostring+"-"+dropdownlist2.selectedvalue.tostring()+"-"+dropdownlist3.selectedvalue.tostring()+").toshortdatestring()'
#3
meteor862008-04-14 19:24
为什么前面'convert.todatetime
后面又有个.toshortdatestring()呢?
#4
meteor862008-04-14 19:28
SqlConnection stt = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["stt"]);
         stt.Open();

        DataSet ds2 = new DataSet();
        SqlDataAdapter sda = new SqlDataAdapter("select studentname ,year  from studentinformation where year='Convert.ToDateTime(" + yearlist.SelectedValue.ToString() + "-" + monthlist.SelectedValue.ToString() + "-" + daylist.SelectedValue.ToString() + ").ToShortDateString()'", stt);
        sda.Fill(ds2, "tab1");
        GridView2.DataSource = ds2.Tables["tab1"];
        GridView2.DataBind();
        stt.Close();  
提示说   此句  sda.Fill(ds2, "tab1");    从字符串转换为 datetime 时发生语法错误。

[[it] 本帖最后由 meteor86 于 2008-4-14 19:31 编辑 [/it]]
#5
hebingbing2008-04-14 19:30
你可以试试如果没有前面的那个智能标签会不会出现后面的那个……
原因是因为toshortdatestring()只能是将datetime的转换,没有办法将字符串的转换……前面先转换成datetime型的,然后在转换成短型的……
#6
meteor862008-04-14 19:34
那个问题是明白了
不过它怎么提示后面那里有错呢?
奇妙!
#7
meteor862008-04-14 19:38
我的year在数据库里是datetime   型的长度为 8
#8
hebingbing2008-04-14 20:01
select * from biao where datetime='convert.todatetime(dropdownlist1.selectedvalue.tostring+"-"+dropdownlist2.selectedvalue.tostring()+"-"+dropdownlist3.selectedvalue.tostring()).toshortdatestring()'
笔误……
#9
meteor862008-04-14 20:13
哈哈.现在是说"-"    运算符“-”无法应用于“string”和“string”类型的操作数    .

我开始也是又这种错,不知道什么原因
#10
hebingbing2008-04-14 20:23
你稍微变通一下不成吗?非要我写成什么样的就写成什么样的……
string a=dropdownlist1.selectedvalue.tostring+"-"+dropdownlist2.selectedvalue.tostring()+"-"+dropdownlist3.selectedvalue.tostring();
然后……用a……
或者在上面的代码上加/或@……
1