当我想获取特定日期的数据时,我的代码出现问题! 我的sql语句:
MySqlCommand cmd = new MySqlCommand("select a.acc_id,a.acc_Name,a.acc_Place,b.type,
b.acc_sub_debt,b.acc_sub_payment,
b.acc_sub_returned,b.acc_sub_date,COALESCE(b.acc_sub_note,' ') from accounts a,
account_Details b where a.acc_ID = b.acc_Sub_ID
where b.acc_sub_date = '" + DateTime.Parse(dateTimePicker1.Text).ToShortDateString()
+ "' order by b.id desc", objConn);
错误是:
"You have an error in your SQL syntac check the manual that corresponds to your MySQL server version for the right syntax to use near 'where b.acc_sub_date = '14/2/2015' order by b.id desc' at line 1"
最佳答案
这样做:
string sql =
@"select a.acc_id,a.acc_Name,a.acc_Place,b.type,b.acc_sub_debt,b.acc_sub_payment,b.acc_sub_returned,b.acc_sub_date,COALESCE(b.acc_sub_note,' ')
from accounts a, account_Details b
where a.acc_ID = b.acc_Sub_ID and b.acc_sub_date = @subDate
order by b.id desc";
MySqlCommand cmd = new MySqlCommand(sql, objConn);
cmd.Parameters.Add("@subDate", MySqlDbType.Date).Value = DateTime.Parse(dateTimePicker1.Text);
关于c# - 比较 SQL C# 中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28518489/