尝试更新访问数据库时出现以下错误:“System.Data.OleDb.OleDbException:'查询表达式中的语法错误(缺少运算符)''计算机,Versie ='一个'WHERE ProductId = 3'。'" [英] Following error when trying to update access database :"System.Data.OleDb.OleDbException: 'Syntax error (missing operator) in query expression ''Computer, Versie='One' WHERE ProductId = 3'.'"

查看:159
本文介绍了尝试更新访问数据库时出现以下错误:“System.Data.OleDb.OleDbException:'查询表达式中的语法错误(缺少运算符)''计算机,Versie ='一个'WHERE ProductId = 3'。'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好


对于学校项目,我正在开发一个简单的程序,可以在访问数据库中插入,删除和更新记录。


插入和删除工作正常但在尝试更新时我收到以下错误:System.Data.OleDb.OleDbException:'查询表达式中的语法错误(缺少运算符)''计算机,Versie ='One'WHERE ProductId = 3'。


以下代码的屏幕截图:


public static void UpdateProduct(Product product)

         {

            string sql = string.Format(" UPDATE tblProducten set Merk ='{0}'," +

           ;     " Soort ='{1},Versie ='{2}'WHERE ProductId = {3}",

                 product.Merk,product.Soort,product.Versie,product.ProductId);

  ;           OleDbConnection连接=新的OleDbConnection(Connectiestring);

            connection.Open();
$


            OleDbCommand command = new OleDbCommand(sql,connection);

            OleDbDataAdapter adapter = new OleDbDataAdapter();

            adapter.UpdateCommand = command;

            adapter.UpdateCommand.ExecuteNonQuery(); //在此行收到错误



            connection.Close();

        }


有关如何使更新部分正常工作的任何想法?


非常感谢提前



Jonathan

解决方案

您可以使用Quickwatch转到对象并查看其内部找到它要执行的T-SQL。您可以为对象复制T-SQL,然后转到MS SQL Sever Management Studio并通过T-SQL进入新查询并执行T-SQL
,它将告诉语法错误在哪里T-SQL。


https://msdn.microsoft.com /en-us/library/0taedcee.aspx


adapter.UpdateCommand.ExecuteNonQuery();


查看上面的对象,找到它试图执行的T-SQL。


Hi

For a school project I'm working on a simple program that can insert, delete and update records into an access database.

Insert and delete works just fine but when trying to update I get the following error : System.Data.OleDb.OleDbException: 'Syntax error (missing operator) in query expression ''Computer, Versie='One' WHERE ProductId = 3'.

Screenshot of the code below :

public static void UpdateProduct (Product product)
        {
            string sql = string.Format("UPDATE tblProducten set Merk ='{0}', " +
                "Soort= '{1}, Versie='{2}' WHERE ProductId = {3}",
                product.Merk, product.Soort, product.Versie, product.ProductId);
            OleDbConnection connection = new OleDbConnection(Connectiestring);
            connection.Open();

            OleDbCommand command = new OleDbCommand(sql, connection);
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter.UpdateCommand = command;
            adapter.UpdateCommand.ExecuteNonQuery(); //getting the error on this line

            connection.Close();
        }

Any ideas on how to make the update part work correctly?

Many thanks in advance

Jonathan

解决方案

You can use Quickwatch an go to the object and look inside of it to find the T-SQL that it is going to execute. You can copy the T-SQL out for the object and go to MS SQL Sever Management Studio and past the T-SQL into the New Query and Execute the T-SQL that will tell where the syntax error is at in the T-SQL.

https://msdn.microsoft.com/en-us/library/0taedcee.aspx

adapter.UpdateCommand.ExecuteNonQuery();

Look inside the above object and find the T-SQL it is trying to execute.


这篇关于尝试更新访问数据库时出现以下错误:“System.Data.OleDb.OleDbException:'查询表达式中的语法错误(缺少运算符)''计算机,Versie ='一个'WHERE ProductId = 3'。'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆