0

我想从 DATE 来自的表中选择所有数据DateTimePicker

这是我到目前为止的代码:

MySqlConnection connection = new MySqlConnection(MyConnection);
connection.Open();
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT * FROM income_table WHERE income_date='" + 
                   dateShower.Value + "';";
cmd.Connection = connection;
MySqlDataReader myDataReader = cmd.ExecuteReader();
while (myDataReader.Read())
{
    txtIncomeList.Text = Convert.ToString(myDataReader["income_subcategory"] + 
                           "\t\t" + myDataReader["income_amount"] + "\r\n" +
                           myDataReader["income_vendor"]+ "\t\t" + 
                           myDataReader["income_paidby"]+"\r\n\r\n");
}
4

1 回答 1

2

sql 查询中的问题,您将 datetimepicker 值(日期和时间)与无法检索任何数据的“income_date”字段数据匹配,您必须编辑查询以比较两个范围之间的日期,如下所示:

"SELECT * FROM income_table WHERE income_date > = '" + dateShower.Value.Date.ToString("yyyyMMdd") + " 00:00:00" + "' and income_date <= '" + dateShower.Value.Date.ToString("yyyyMMdd") + " 23:59:59" + "'"; 
于 2013-09-08T09:37:43.480 回答