DateTime fromDate = dateTimePicker1.Value, toDate = dateTimePicker2.Value;
string query2 = "select * from Sales where DatePurchased >= '" + fromDate.ToShortDateString() + "' AND DatePurchased <='" + toDate.ToShortDateString() + "'";
using (OleDbConnection conn2 = new OleDbConnection(connStr))
{
using (OleDbCommand command = new OleDbCommand(query2, conn2))
{
command.Connection = conn2;
conn2.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
graphics.DrawString(string.Format("{0:000000}", reader.GetInt32(0)), font, new SolidBrush(Color.Black), startX, startY + offset);
graphics.DrawString(reader.GetString(1), font, new SolidBrush(Color.Black), startX+90, startY + offset);
graphics.DrawString(reader.GetString(2), font, new SolidBrush(Color.Black), startX + 250, startY + offset);
graphics.DrawString(Convert.ToString(reader.GetDouble(3)), font, new SolidBrush(Color.Black), startX + 500, startY + offset);
startY += 35;
}
}
}
我在這裏歌廳的錯誤:查詢過濾數據庫
OleDbDataReader reader = command.ExecuteReader();
錯誤
「OleDbException是未處理:條件表達式中數據類型不匹配。」
我不知道該怎麼辦,我的數據庫中的數據是日期/時間。請幫助
前工作,我把一個'breakpoint'本着'串QUERY2 = 「SELECT * FROM銷售,其中購置日期> =「」 + fromDate.ToShortDateString() +「'AND DatePurchased <='」+ toDate.ToShortDateString()+「'」;'看看'query2'是什麼? –
抱歉,但我不知道如何放置斷點。你能教我如何? – user3221836
檢查日期格式...什麼是「fromDate」和「toDate」是YYYY-MM-DD而不是ToShortDateString() –