在数据库中按照月份查找问题!请高手指点!顶这有分!
jgsj 在数据库中是时间字段 smalldatetime 类型!
我在程序中做了按钮比方说以下代码 par_1 是1月的按钮 我一点击查询出来的都是1月份的记录那 int jgsj = 这个变量如何声明呢????
private void par_1_Click(object sender, System.EventArgs e)
{
int jgsj = 1
SqlConnection con = DBCon.createCon();
con.Open();
SqlCommand cmd = new SqlCommand( "select * from cnatword where jgsj= ' "+jgsj+ " ' ",con);
cmd.ExecuteNonQuery();
con.Close();
}
------解决方案--------------------SqlCommand cmd = new SqlCommand( "select * from cnatword where jgr= ' "+jgr+ " ' DateDiff(m,jgsj, '2007-01-01 ') = 0 ",con);
===>
SqlCommand cmd = new SqlCommand( "select * from cnatword where DateDiff(m,jgsj, '2007-01-01 ') = 0 ",con);
------解决方案--------------------SqlCommand cmd = new SqlCommand( "select * from cnatword where jgr= ' "+jgr+ " ' and DateDiff(m,jgsj, '2007-01-01 ') = 0 ",con);
------解决方案--------------------cssasp() ( ) 信誉:100 Blog 2007-02-28 16:09:56 得分: 0
那最后= 0 什么意思?
----------
和 '2007-01-01 '按月比較,如果等於0,就是得到和 '2007-01-01 '月份相同的數據