我原来是用SQL2005的,现在用ACCESS ,在SQL里功能是正常的,问题应该就是出在时间上,我是用TEXTBOX提交时间的,ACCESS表里的时间格式是 日期/时间
private void button1_Click(object sender, EventArgs e)
{
show();
}
private void show()
{
string strPath = "\\\\192.168.1.12\\共享文件\\求职名册" + "\\AAA.mdb";
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source='" + strPath + "'";
OleDbConnection oleCon = new OleDbConnection(ConStr);
StringBuilder strSQL = new StringBuilder();
oleCon.Open();
DataTable dt = new DataTable("卡");
OleDbDataAdapter da = new OleDbDataAdapter(getsql(),oleCon);
da.Fill(dt);
dataGridView1.DataSource = dt.DefaultView;
oleCon.Close(); }
private string getsql()
{ string sql = "select * from 卡 where id>=0"; if (textBox4.Text != null && textBox4.Text != "" && textBox5.Text != null && textBox5.Text != "")
sql += " and indate between '" + DateTime.Parse(textBox4.Text) + "' and '" + DateTime.Parse(textBox5.Text) + "'";//应该就是这里有问题,我不知道ACCESS的时间转换是否正确
if (comboBox2.Text != null && comboBox2.Text != "") sql += " and 卡状态='" + comboBox2.Text + "'"; return sql += "order by id desc";
}
大家帮帮我吧!
private void button1_Click(object sender, EventArgs e)
{
show();
}
private void show()
{
string strPath = "\\\\192.168.1.12\\共享文件\\求职名册" + "\\AAA.mdb";
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source='" + strPath + "'";
OleDbConnection oleCon = new OleDbConnection(ConStr);
StringBuilder strSQL = new StringBuilder();
oleCon.Open();
DataTable dt = new DataTable("卡");
OleDbDataAdapter da = new OleDbDataAdapter(getsql(),oleCon);
da.Fill(dt);
dataGridView1.DataSource = dt.DefaultView;
oleCon.Close(); }
private string getsql()
{ string sql = "select * from 卡 where id>=0"; if (textBox4.Text != null && textBox4.Text != "" && textBox5.Text != null && textBox5.Text != "")
sql += " and indate between '" + DateTime.Parse(textBox4.Text) + "' and '" + DateTime.Parse(textBox5.Text) + "'";//应该就是这里有问题,我不知道ACCESS的时间转换是否正确
if (comboBox2.Text != null && comboBox2.Text != "") sql += " and 卡状态='" + comboBox2.Text + "'"; return sql += "order by id desc";
}
大家帮帮我吧!
换成
Convert.ToDateTime(textBox4.Text);
试试!
2,
SQL 不会有问题的,我在SQL2005里是对的呀
会不会是卡状态出的问题,建议你调试获取一下你的SQL语句看看