我使用sql developer
创建表create table tablenodes
(
nodeNo int ,
nodeName varchar2(50),
centerX int ,
centerY int,
radius number(7,2),
fileNo int
)
我想更新此表中的所有字段,因此我编写了以下代码:
Friend Function UpdateNodeToTable(ByVal FN As Integer, ByVal nd As classNode) As Boolean
Try
Dim con As New OracleConnection
con.ConnectionString = "Persist Security Info=False;User ID=manal;password=manal;Data Source=xe"
con.Open()
Dim cmd As New OracleCommand
cmd.CommandType = CommandType.Text
cmd.Connection = con
cmd.CommandText = "update tablenodes set nodeName=@NodeName, centerX = @NodeCenterX," & _
"centerY= @NodeCenterY , radius= @NodeRadius where nodeNo= @nodeNum and fileno= @FileNum"
cmd.Parameters.Add("@NodeNum", OracleDbType.Int32).Value = nd.pID
cmd.Parameters.Add("@NodeName", OracleDbType.Varchar2).Value = nd.pName
cmd.Parameters.Add("@NodeCenterX", OracleDbType.Int32).Value = nd.pCenter.X
cmd.Parameters.Add("@NodeCenterY", OracleDbType.Int32).Value = nd.pCenter.Y
cmd.Parameters.Add("@NodeRadius", OracleDbType.Double).Value = nd.pRadius
cmd.Parameters.Add("@FileNum", OracleDbType.Int32).Value = FN
Dim success As Boolean
If cmd.ExecuteNonQuery() = 1 Then
success = True
Else
success = False
End If
cmd.Dispose()
con.Close()
con.Dispose()
Return success
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
我在更新语句时遇到问题,无法正确编写,每次我尝试编辑它时,都会给我不同的错误(ora-01036非法变量名称/编号,缺少表达式,标识符无效)。
答案 0 :(得分:1)
你UPDATE
语句中的绑定变量应该以冒号为前缀,而不是@
符号
cmd.CommandText = "update tablenodes set nodeName=:NodeName, centerX = :NodeCenterX," & _
"centerY= :NodeCenterY , radius= :NodeRadius where nodeNo= :nodeNum and fileno= :FileNum"
你没有设置参数
的前缀 cmd.Parameters.Add("NodeNum", OracleDbType.Int32).Value = nd.pID
cmd.Parameters.Add("NodeName", OracleDbType.Varchar2).Value = nd.pName
cmd.Parameters.Add("NodeCenterX", OracleDbType.Int32).Value = nd.pCenter.X
cmd.Parameters.Add("NodeCenterY", OracleDbType.Int32).Value = nd.pCenter.Y
cmd.Parameters.Add("NodeRadius", OracleDbType.Double).Value = nd.pRadius
cmd.Parameters.Add("FileNum", OracleDbType.Int32).Value = FN