存储过程访问错误 [英] error in stored procedure Access

查看:90
本文介绍了存储过程访问错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个查询,该查询是:SELECT Replace(column_name,a,b) AS expr1 FROM table1;该查询的名称是:文件路径.

I have created a query which is: SELECT Replace(column_name,a,b) AS expr1 FROM table1; the name of this query is:filepath.

我已经用C#编写了以下代码.当我编译代码时,它会出现 PROCEDURE子句中的语法错误.

I have wrote the following code in C#. when i compile the code it Syntax error in PROCEDURE clause.

            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值可以像这样:D:/myfile/pictures/cars/ //newfile值可以像这样:D:/myfile/pictures/jeeps/

//oldefile value can be like this: D:/myfile/pictures/cars/ //newfile value can be like this: D:/myfile/pictures/jeeps/

我想用另一个字符串替换一个字符串而不修改整个行..我以为replace可以用,但是没有:(

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 :(

访问版本为:2007.

access version is:2007.

任何想法或帮助将不胜感激.

any idea or help will be greatly appreciated.

非常感谢.

推荐答案

尝试通过以下方式更改命令文本

Try changing your commandtext with

cmd1.CommandText = "EXECUTE yourProcedureName";

编辑,因为您的过程已正确调用,您需要解决缺少的替换"功能(顺便说一句,您是否曾尝试过Vincent Vancalbergh的建议,以查看替换是否可以工作?会容易得多....)

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....)

我在评论中说的是,您可以选择表的内容,用c#代码执行替换,并(如果需要)使用新值更新表.

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.

您的选择将变为:

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
   // ...
}

这篇关于存储过程访问错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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