OleDbCommand存储过程找不到访问查询 [英] OleDbCommand Stored Procedure Cannot Find Access Query
问题描述
我正在尝试使用OleDbCommand在C#中运行Access附加查询.
I am attempting to run an Access append query in C# using OleDbCommand.
作为测试,我在数据库中创建了两个查询(一个是另一个的副本)
As a test I created two queries in the database (one a copy of the other)
-
AppendMe
-
Append Me
AppendMe
Append Me
AppendMe
可以正常工作,但是当我尝试执行第二个Append Me
时,我得到一个OleDbException
找不到输入表或查询'Append'".换句话说,它只能看到字符串的第一个单词.我试过操纵字符串(使用逐字字符串等)
什么都行不通.
我正在使用c#Express 2010和Access 2003
这是代码的一部分
AppendMe
works fine but when I attempt to execute the second Append Me
I get an OleDbException
"cannot find the input table or query 'Append'" In other words its only seeing the first word of the string. I've tried manipulating the string (using verbatim string etc)
Nothing works.
I am using c# Express 2010 and Access 2003
Here's an extract of the code
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
string StdProc = "Append Me";
OleDbCommand cmd = new OleDbCommand(StdProc, conn);
cmd.CommandType = CommandType.StoredProcedure;
OleDbDataReader rdr = cmd.ExecuteReader();
推荐答案
如果SQL标识符包含有趣的字符(例如空格),则必须将其括在方括号中.
If an SQL indentifier contains funny characters, such as a space, it must be enclosed in square brackets.
[Append Me]
这篇关于OleDbCommand存储过程找不到访问查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!