更新mySQL时ASP错误“键列信息不足或不正确。”

时间:2022-03-05 04:44:57

I have the following subroutine in a classic ASP class that calls the ADO UPDATE method. I'm using mySQL db using ODBC driver 5.1.

我在调用ADO UPDATE方法的经典ASP类中有以下子例程。我使用ODBC驱动程序5.1使用mySQL数据库。

If I all the subroutine I get the following error:

如果我所有的子程序,我得到以下错误:

Microsoft Cursor Engine error '80004005' Key column information is insufficient or incorrect. Too many rows were affected by update.

Microsoft游标引擎错误“80004005”键列信息不足或不正确。更新会影响太多行。

Public Sub Update(table,id_field,id,fields,values)
    Dim yy
    Dim strQuery
    Dim strFields
    Const adOpenDynamic = 2
    Const adLockOptimistic = 3
    Const adCmdText = 1
    strQuery = ""
    For yy = LBound(fields) to UBound(fields)
            strQuery = strQuery & fields(yy) & ", "
    Next
    strQuery = Left(strQuery, Len(strQuery) - 2)
    strQuery = "select " & strQuery & " from " & table & " where " & id_field & "=" & id
    i_objRS.CursorLocation = 3
    i_objRS.Open strQuery, i_objDataConn, adOpenDynamic, adLockOptimistic, adCmdText
    For yy = 0 To UBound(fields)
            i_objRS(fields(yy)) = values(yy)
    Next
    i_objRS.Update
    i_objRS.Close
End Sub

I've tried changing the cursorlocation property and the open parameters but still cannot get it to work. The table I'm updating has a unique auto id which is the primary key.

我已经尝试更改了cursorlocation属性和open参数,但仍无法使其工作。我正在更新的表有一个唯一的自动ID,这是主键。

2 个解决方案

#1


0  

The first thing to do in diagnosing dynamically created SQL is to examine the SQL string actually created. However using a dynamic cursor to perform updates is not a good way to acheive an update for a row.

诊断动态创建的SQL的第一件事是检查实际创建的SQL字符串。但是,使用动态游标执行更新并不是实现行更新的好方法。

Use an ADODB.Command object instead and create an Update command. Note don't concatenate the values into the created SQL command. Instead use parameter place marks (usually ? but I can't remember if that varies my DBengine (I'm not a mySQL bod)) and add parameters to the ADODB.Command parameters collection.

请改用ADODB.Command对象并创建Update命令。注意不要将值连接到创建的SQL命令中。而是使用参数位置标记(通常?但我不记得是否会改变我的DBengine(我不是mySQL身体))并将参数添加到ADODB.Command参数集合中。

#2


0  

Hmm. Do you need to do this through ADO? Try running the query against a connection object and see what happens?

嗯。你需要通过ADO做到这一点吗?尝试对连接对象运行查询,看看会发生什么?

#1


0  

The first thing to do in diagnosing dynamically created SQL is to examine the SQL string actually created. However using a dynamic cursor to perform updates is not a good way to acheive an update for a row.

诊断动态创建的SQL的第一件事是检查实际创建的SQL字符串。但是,使用动态游标执行更新并不是实现行更新的好方法。

Use an ADODB.Command object instead and create an Update command. Note don't concatenate the values into the created SQL command. Instead use parameter place marks (usually ? but I can't remember if that varies my DBengine (I'm not a mySQL bod)) and add parameters to the ADODB.Command parameters collection.

请改用ADODB.Command对象并创建Update命令。注意不要将值连接到创建的SQL命令中。而是使用参数位置标记(通常?但我不记得是否会改变我的DBengine(我不是mySQL身体))并将参数添加到ADODB.Command参数集合中。

#2


0  

Hmm. Do you need to do this through ADO? Try running the query against a connection object and see what happens?

嗯。你需要通过ADO做到这一点吗?尝试对连接对象运行查询,看看会发生什么?