gpt4 book ai didi

c# - 根据 DateTimePicker 值从 MySQL 数据库表中选择所有数据

转载 作者:行者123 更新时间:2023-11-29 08:23:20 24 4
gpt4 key购买 nike

我想从表中选择所有数据,其中日期将来自 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");
}

最佳答案

sql 查询中的问题是,您将 datetimepicker 值(日期和时间)与“venue_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" + "'"; 

关于c# - 根据 DateTimePicker 值从 MySQL 数据库表中选择所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18679254/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com