在MS Access中插入语句问题 [英] Insert Statement Problem in MS Access

查看:63
本文介绍了在MS Access中插入语句问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有问题就是这样。我想在MS Access Table上插入数据,但它在INSERT INTO语句中给出了语法错误。



我的代码是这个





Hi
I have problem is that. I want to insert data on MS Access Table but it gives Syntax error in INSERT INTO statement.

my code is this


int pcid = int.Parse(drpProduct.SelectedValue);
            string qury = "Insert into Product_Information(PCId,ImagePath,Names,Code) values(" + pcid + ",'" + uploadPath + "','" + txtImageName.Text + "','" + txtImageCode.Text + "') ";
           
            OleDbCommand oleDbCommand = new OleDbCommand(qury, oleDbConnection);           
            if (oleDbConnection.State != ConnectionState.Open)
                oleDbConnection.Open();
            int i = oleDbCommand.ExecuteNonQuery();
            if (i > 0)
            {
                txtImageCode.Text = txtImageName.Text = string.Empty;
            }

推荐答案

@BulletVictim 是正确的。



当你提到特定数据库的任何保留关键字时会发生这个问题。



参考 - 访问2007保留字和符号 [ ^ ]。br />
这里列出了所有关键字。

从您的查询中,名称也出现在列表中。



因此,当您使用时它,它将引用关键字而不是表的列。

要解决此问题,我们将其包装在Square Brackets中,以便它不会引用默认关键字。
@BulletVictim is correct.

This issue happens when you mention any reserved keyword of a particular Database.

Refer - Access 2007 reserved words and symbols[^].
Here all the keywords are listed.
From your query, "Names" is also present in the list.

So, when you use it, it will refer to the keyword and not the column of Table.
To resolve this, we wrap it inside the Square Brackets, so that it will not refer to the default keyword.


这篇关于在MS Access中插入语句问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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