关键字“订单"附近的语法不正确-订单为列名 [英] Incorrect syntax near the keyword 'Order' - Order is column name

查看:46
本文介绍了关键字“订单"附近的语法不正确-订单为列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到以下异常:

 关键字"Order"附近的语法不正确. 

我有一个带有以下列的表:名称信用扩展 Order . Order 的类型为 bigint .现在,当我将 INSERT 的单个记录转到该表中时,它给了我上面的异常.

我已将其放在try/catch块中并捕获了异常,我已设置了断点,并且除了上述消息外,它不显示任何 .

有人可以帮助阐明这一点吗?我坐在这里,挠头想知道到底发生了什么,我只是想不通.我看不到哪里出了问题.

 试试{//插入数据库sqlconnection = new SqlConnection(@"Data Source = sblah blah blah ...故意删除;");sqlconnection.Open();使用(var命令=新的SqlCommand(插入图像(名称,信用,扩展名,顺序)值(@ Name,@ Credits,@ Extension,@ Order)",sqlconnection){command.CommandTimeout = 240;command.Parameters.AddWithValue("Name",workingPicture.Properties.Filename);command.Parameters.AddWithValue("Credits",workingPicture.Properties.Credits);command.Parameters.AddWithValue("Extension",workingPicture.Properties.Extension);command.Parameters.AddWithValue("Order",workingPicture.Properties.Order);command.ExecuteNonQuery();doneUpdatingDB = true;}}捕获(异常异常){MessageBox.Show(exception.Message);doneUpdatingDB = false;} 

Order 的值是 0 .

解决方案

Order是SQL中的关键字,请更改数据库中字段的名称,或在诸如[[order]之类的order关键字旁加上[].>

I keep getting the following exception:

Incorrect syntax near the keyword 'Order'.

I have a TABLE with columns: Name, Credits, Extension, Order. Order is of type bigint. Now when I go to INSERT a single record into this table, it gives me the above exception.

I have put it in a try/catch block and caught the exception, I have set breakpoints and it does not reveal anything other than the above message.

Can anybody please help shed some light on this? I'm sitting here, scratching my head wondering what the heck is going on and I just can't figure it out. I don't see where I've gone wrong.

        try
        {
            // Insert into database
            sqlconnection = new SqlConnection(@"Data Source=sblah blah blah... intentionally  removed;");

            sqlconnection.Open();

            using (var command = new SqlCommand("Insert Into Images(Name, Credits, Extension, Order) VALUES (@Name, @Credits, @Extension, @Order)", sqlconnection))
            {
                command.CommandTimeout = 240;

                command.Parameters.AddWithValue("Name", workingPicture.Properties.Filename);
                command.Parameters.AddWithValue("Credits", workingPicture.Properties.Credits);
                command.Parameters.AddWithValue("Extension", workingPicture.Properties.Extension);
                command.Parameters.AddWithValue("Order", workingPicture.Properties.Order);

                command.ExecuteNonQuery();

                doneUpdatingDB = true;
            }
        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.Message);
            doneUpdatingDB = false;
        }

The value of Order is 0.

解决方案

Order is the keyword in the SQL, Change the name of the field in the DB or make [] around the order keyword like "[order]"

这篇关于关键字“订单"附近的语法不正确-订单为列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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