当我想获取特定日期的数据时,我的代码有问题!
我的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);


错误是:


  “您的SQL语法错误,请查看
  对应于您的MySQL服务器版本以使用正确的语法
  第'line.acc_sub_date = '14 / 2/2015'by b.id desc order'附近
  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);

10-04 15:49