简体   繁体   English

存储过程访问错误

[英]error in stored procedure Access

I have created a query which is: SELECT Replace(column_name,a,b) AS expr1 FROM table1; 我创建了一个查询,它是: SELECT Replace(column_name,a,b) AS expr1 FROM table1; the name of this query is: filepath . 该查询的名称是: filepath

I have wrote the following code in C#. 我已经在C#中编写了以下代码。 when i compile the code it Syntax error in PROCEDURE clause. 当我编译代码时,PROCEDURE子句中的语法错误。

            OleDbCommand cmd1 = new OleDbCommand();
            cmd1.Connection= ren_connection1;
            cmd1.CommandType = CommandType.Text;
            cmd1.CommandText = "Execute filepath";

            OleDbParameter oldfilevalue = new OleDbParameter();
            oldfilevalue.ParameterName = "a";
            oldfilevalue.OleDbType = OleDbType.VarChar;
            oldfilevalue.Direction = ParameterDirection.Input;
            oldfilevalue.Value = oldname2;

            OleDbParameter newfilevalue = new OleDbParameter();
            newfilevalue.ParameterName = "b";
            newfilevalue.OleDbType = OleDbType.VarChar;
            newfilevalue.Direction = ParameterDirection.Input;
            newfilevalue.Value = oldname1;

            cmd1.Parameters.Add(oldfilevalue);
            cmd1.Parameters.Add(newfilevalue);

            i = cmd1.ExecuteNonQuery();

//oldefile value can be like this: D:/myfile/pictures/cars/ //newfile value can be like this: D:/myfile/pictures/jeeps/ // oldefile值可以像这样:D:/ myfile / pictures / cars / // newfile值可以像这样:D:/ myfile / pictures / jeeps /

i want to replace in a row a string with another string without modifying the whole row..and i thought replace will work but it didnt :( 我想用另一个字符串替换一个字符串而不修改整个行..我以为替换会起作用,但没有:(

access version is:2007. 访问版本是:2007。

any idea or help will be greatly appreciated. 任何想法或帮助将不胜感激。

Thanks alot. 非常感谢。

I am afraid Replace is only available if you are running within Access, as Vincent mentions, it is a VBA function, not a Jet/ACE function. 恐怕只有在Access中运行时,Replace才可用,正如Vincent所说,它是VBA功能,而不是Jet / ACE功能。 Also discussed: Exception when trying to execute "REPLACE" against MS Access . 还讨论了: 尝试对MS Access执行“ REPLACE”时发生异常 I have replied to what i think is your first question, update table access , with a possible solution. 我已经回答了我认为的第一个问题,即使用可能的解决方案更新表访问权限

Try changing your commandtext with 尝试使用以下命令更改命令文本

cmd1.CommandText = "EXECUTE yourProcedureName";

Edit now that your procedure is invoked correctly you need to work around the missing "Replace" function (btw, have you tried Vincent Vancalbergh's suggestion to see if "Replace can be made to work? That would be much easier....) 现在进行编辑 ,以正确调用过程,您需要解决丢失的“替换”功能(顺便说一句,您是否尝试过文森特·范卡尔伯格的建议,看看“替换是否可以工作?这会容易得多。。。)

What I was saying in the comments is that you could select the content of the table, perform the replace in c# code and (if needed) update your table with the new values. 我在评论中说的是,您可以选择表的内容,用c#代码执行替换,并(如果需要)使用新值更新表。

your select becomes: 您的选择将变为:

SELECT table1_id, column_name FROM table1;

and your code changes like this: 和您的代码更改如下:

//you should change ExecuteNonQuery to ExecuteReader, since you want 
// to read the results of your SELECT 
OleDbDataReader rdr= cmd1.ExecuteReader();

//Iterate through the table
while(rdr.Read())
{
   string currentValue=rdr["column_name"].ToString();
   string newValue = currentValue.Replace(a, b);

   //now do what you need with the row
   // ...
}

I found the following here : 我在这里找到以下内容:

Prior to a company wide upgrade to XP there was no problem with access databases, so I am not sure if this would be a solution to your issue. 在公司范围内升级到XP之前,访问数据库没有问题,因此我不确定这是否可以解决您的问题。 But I had a problem similar to yours after an upgrade to XP from 2000 with some access databases. 但是从2000年升级到具有某些访问数据库的XP之后,我遇到了一个与您类似的问题。 Undefined Function "Replace" errors started to pop up. 未定义的功能“替换”错误开始弹出。 At the end of the day it turned out to be the version of VBA installed. 最终,结果证明是安装的VBA版本。 6.0 versus 6.3. 6.0和6.3。 The problem machines had 6.0 installed. 问题机器已安装6.0。 Start access Help -> About MS Access -> SYSTEM INFO -> APPLICATIONS -> Microsoft Access 2000 -> SUMMARY. 开始访问帮助->关于MS Access->系统信息->应用程序-> Microsoft Access 2000->摘要。 The VBA version of 6.00 produced the error, VBA version 6.03 no problem. VBA版本6.00产生了错误,VBA版本6.03没问题。 Take Care, Nick 保重,尼克

Now the question is, what VBA version are you using? 现在的问题是,您使用的是哪个VBA版本?

The solution is in @onedaywhen's answer her: 解决方案是在@onedaywhen回答她时:

Exception when trying to execute "REPLACE" against MS Access 尝试对MS Access执行“ REPLACE”时发生异常

It uses Mid(), Len() and InStr() in place of Replace(). 它使用Mid(),Len()和InStr()代替Replace()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM