我手动绑定了两个combobox,3和4,一个的ITEMS从1到12,一个从1-31,代表月份和日期,但是如下语句却查询不到数据:
select * from person inner join Department on person.cDept_num=Department.cDepCode where month(person.dBirthDate)='" +comboBox3.SelectedItem.ToString() + "' and day(person.dBirthDate)='" +comboBox4.SelectedItem.ToString()+ "'
而
select * from person inner join Department on person.cDept_num=Department.cDepCode
where month(person.dBirthDate)='7'
and day(person.dBirthDate)='4' 却能查询到数据(数据库中有一个dBirthDate为2007-7-4的记录)
select * from person inner join Department on person.cDept_num=Department.cDepCode where month(person.dBirthDate)='" +comboBox3.SelectedItem.ToString() + "' and day(person.dBirthDate)='" +comboBox4.SelectedItem.ToString()+ "'
而
select * from person inner join Department on person.cDept_num=Department.cDepCode
where month(person.dBirthDate)='7'
and day(person.dBirthDate)='4' 却能查询到数据(数据库中有一个dBirthDate为2007-7-4的记录)
看看
comboBox3.SelectedItem.ToString()
comboBox4.SelectedItem.ToString()
分别是什么
comboBox3.SelectedItem.ToString()
这样取值,用
comboBox1.SelectedValue.ToString()
如果comboBox1的ValueMember绑定的并不是你要查询的值,说明一下,再给你看下如何做
我测试过了 是正确的!!
错误原因 应该在 你没有贴出来的代码上面 :
=============
SqlConnection conn = new SqlConnection("Server=.;Database=testManage;Integrated Security=SSPI");
string str = "select * from stuInfo where month(stuInfo.FBirDate)='"+cobShow.SelectedItem.ToString()+"' and day(stuInfo.FBirDate)='"+cb2.SelectedItem.ToString()+"'";
SqlDataAdapter da = new SqlDataAdapter(str,conn);
DataSet ds = new DataSet();
da.Fill(ds); MessageBox.Show(ds.Tables[0].Rows.Count.ToString());
selectvalue
selecttext
这样的