【问题标题】:INSERT SQL Updatable Query using proper MS Access cmd Command使用正确的 MS Access cmd 命令插入 SQL 可更新查询
【发布时间】:2015-06-08 19:24:48
【问题描述】:

当我在下面的另一台机器上运行时,访问数据库查询失败

Microsoft Word 2013 视觉工作室 2013 Windows 8.1(64 位)

在另一台机器上,相同的查询运行下面的配置

Microsoft Word 2010 视觉工作室 2010 Windows 7(32 位)

下面的查询

 con.Open();

            string cb = "insert Into Salcmd = new sqles(InvoiceNo,InvoiceDate,CustomerID,SubTotal,VATPercentage,VATAmount,GrandTotal,TotalPayment,PaymentDue,Remarks) VALUES ('" + txtInvoiceNo.Text + "',#" + dtpInvoiceDate.Text + "#,'" + txtCustomerID.Text + "'," + txtSubTotal.Text + "," + txtTaxPer.Text + "," + txtTaxAmt.Text + "," + txtTotal.Text + "," + txtTotalPayment.Text + "," + txtPaymentDue.Text + ",'" + txtRemarks.Text + "')";
            cmd = new OleDbCommand(cb);
            cmd.Connection = con;
            cmd.ExecuteReader();
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
            con.Close();

查询依赖有问题请告诉我

【问题讨论】:

  • 你能发布错误信息吗?
  • 1) 插入语句中的语法错误 2) 操作必须使用可更新查询。

标签: c# sql visual-studio-2013 sql-insert ms-access-2013


【解决方案1】:

您的 INSERT SQL 语句包含语法错误:

string cb = "insert Into Salcmd = new sqles(InvoiceNo,InvoiceDate,CustomerID,SubTotal,VATPercentage,VATAmount,GrandTotal,TotalPayment,PaymentDue,Remarks) VALUES ('" + txtInvoiceNo.Text + "',#" + dtpInvoiceDate.Text + "#,'" + txtCustomerID.Text + "'," + txtSubTotal.Text + "," + txtTaxPer.Text + "," + txtTaxAmt.Text + "," + txtTotal.Text + "," + txtTotalPayment.Text + "," + txtPaymentDue.Text + ",'" + txtRemarks.Text + "')"

应该是这样的:

string cb = "INSERT INTO sqles(InvoiceNo,InvoiceDate,CustomerID,SubTotal,VATPercentage,VATAmount,GrandTotal,TotalPayment,PaymentDue,Remarks) VALUES ('" + txtInvoiceNo.Text + "',#" + dtpInvoiceDate.Text + "#,'" + txtCustomerID.Text + "'," + txtSubTotal.Text + "," + txtTaxPer.Text + "," + txtTaxAmt.Text + "," + txtTotal.Text + "," + txtTotalPayment.Text + "," + txtPaymentDue.Text + ",'" + txtRemarks.Text + "')"

另外,请尝试:cmd.ExecuteNonQuery() 而不是阅读器。

希望这会有所帮助。

【讨论】:

  • 在您的问题中包含错误消息。最好的问候,
  • 非常感谢您整理
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多