I perform some actions on a table retrieved from a db2 database row by row in a C# project. but when I try to update it using cursors row by row to the database using the following statement an exception is generated:
selectCommand.CommandText = "DECLARE crsr1 CURSOR FOR select * from " + tableName+" ;"
From my understanding of this, using cursors statements of db2 is not supported in .net languages. I am connected to the database using IBM DB2 ODBC drivers.
Is there is any way around using cursors , or if someone can tell whether there is something I am missing here.
I did a lot of searching on net , but not much is available on this problem.
this is the exception I got for the above statement --
"ERROR [42601] [IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token \"DECLARE CRSR1 CURSOR FOR select * from MYTA\" was found following \"BEGIN-OF-STATEMENT\".
Expected tokens may include: \"<space>\". SQLSTATE=42601\r\n"
any help or suggestions are highly appreciated.
我认为您可能希望将其放入proc-通常不会在存储的proc之外执行“声明游标..” {除非您在CLI或其他工具中进行调试}
You should just put the "SELECT" part in the command text and use ExecuteResultSet method of DB2Command to return a resultset that wraps a scrollable updatable cursor.
selectCommand.CommandText = "select * from " + tableName+" ;"
using(var result = selectCommand.ExecuteResultSet(DB2ResultSetOptions.Updatable))
{
while (result.Read())
{
//set value of 2nd column to 'Hello'
result.SetString(1, "Hello");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.