dataadapter.Fill(ds)中条件表达式中的数据类型不匹配

时间:2016-03-24 09:50:02

标签: ms-access-2007 c#-3.0

实际上是我在c#中创建报告,当我选择一个日期并点击show report时,我不得不使用Datetimepicker,Button和datagridview,这给了我dataadapter.Fill(ds)中的错误;线     即时通讯使用访问数据库这里我给我的表结构

AccountNumber--Number
Account-- Memo
Date--Date/Time
Description--Memo
Post_Ref--Memo
Debit--Number
Credit--Number
Balance--Number


private void btnshowreport_Click(object sender, EventArgs e)
        {
 string connetionString = null;
            DateTime startT = new DateTime();
            DateTime endT = new DateTime();
            startT = dateTimePicker1.Value.Date;
            endT = dateTimePicker2.Value.Date;
            connetionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
            cnn.ConnectionString = connetionString;
string sql = "SELECT * FROM Billing where [Date] Between'"+startT+"'And '"+endT+"'";
            OleDbConnection connection = new OleDbConnection(connetionString);
            OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
            DataTable ds = new DataTable();
            connection.Open();
            dataadapter.Fill(ds);
            connection.Close();
            dataGridView1.DataSource = ds;
            show_data();
}

1 个答案:

答案 0 :(得分:0)

您需要适当的日期表达式格式:

string sql = "SELECT * FROM Billing where [Date] Between #" + startT.ToString("yyyy'/'MM'/'dd") + "# And #" + endT.ToString("yyyy'/'MM'/'dd") + "#";