繁体   English   中英

INSERT INTO语句c#.net Winforms Devexpress中的语法错误?

[英]Syntax error in INSERT INTO statement c#.net Winforms Devexpress?

我从DateEdit获取日期,并尝试存储到Access数据库中。 但是它显示这样的错误

Syntax error in INSERT INTO statement.

我的插入语句是这个

 OleDbCommand top = new OleDbCommand("INSERT INTO invoice(invoice_number,order_number,customername,status,subtotal,tax,total,date) VALUES (" + inno + "," + odrno + ",'" + name + "','"+ chk1 +"' ,"+ subtottal +","+ tax +","+total+",'"+date+"')", conn);
 top.ExecuteNonQuery();

除日期剩余值成功存储外,如何存储日期?

我得到这样的DateTime date = dateEdit1.DateTime;

帮我。

DATE是Microsoft Access的reserved keyword 您应该在[DATE]等方括号中使用它

而且您应该始终使用parameterized queries 这类字符串连接对SQL Injection攻击开放。

OleDbCommand top = new OleDbCommand(@"INSERT INTO invoice(invoice_number,order_number,customername,status,subtotal,tax,total,[date]) 
                                     VALUES (@invoice_number, @order_number, @customername, @status, @subtotal, @tax, @total, @date)", conn);
top.Parameters.AddWithValue("@invoice_number", inno);
top.Parameters.AddWithValue("@order_number", odrno);
top.Parameters.AddWithValue("@customername", name);
top.Parameters.AddWithValue("@status", chk1);
top.Parameters.AddWithValue("@subtotal", subtotal);
top.Parameters.AddWithValue("@tax", text);
top.Parameters.AddWithValue("@total", total);
top.Parameters.AddWithValue("@date", date);

通常建议不要在数据库中使用保留关键字作为标识符和对象名。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM