【问题标题】:adding data to oracle database in vb6在vb6中将数据添加到oracle数据库
【发布时间】:2018-02-01 16:03:41
【问题描述】:

我在添加数据 oracle 数据库时遇到问题,它向我显示此消息(“https://ufile.io/lzpuj”)运行时 ORA-00904:“EMPCODE”:无效标识符。 这是科迪:

Dim connEmp As ADODB.Connection
Dim rsEmp As ADODB.Recordset

Private Sub Command1_Click()
   Set rsEmp = New ADODB.Recordset
   rsEmp.Open "select * from tablebooks where empcode = '" & Text1.Text & "'", 
   connEmp, adOpenKeyset, adLockReadOnly, adCmdText
   If rsEmp.RecordCount <> 0 Then
      MsgBox " ! åÐÇ ÇáßÊÇÈ ãæÌæÏ ÈÇáÝÚá "
      rsEmp.Close
      Set rsEmp = Nothing
      Exit Sub
   Else
      Set rsEmp = New ADODB.Recordset
      rsEmp.Open "select * from tablebooks where empcode = '" & Text1.Text & "'", 
      connEmp, adOpenKeyset, adLockPessimistic, adCmdText
      rsEmp.AddNew

      rsEmp!Book_no = Val(Trim(Text1.Text))
      rsEmp!Book_name = Trim(Text2.Text)
      rsEmp!Author_name = Trim(Text10.Text)
      rsEmp!Edition_no = Val(Trim(Text3.Text))
      rsEmp!Publisher_place = Trim(Text11.Text)
      rsEmp!Part_no = Val(Trim(Text5.Text))
      rsEmp!Book_cost = Trim(Text6.Text)
      rsEmp!Place_book = Trim(Text7.Text)
      rsEmp!Note = Trim(Text9.Text)

      rsEmp!Date_publishing = DTPicker1.Value
      rsEmp!Subject = Trim(Combo4.Text)
      rsEmp!State = Trim(Combo4.Text)
      rsEmp.Update
      connEmp.Execute "commit"
      rsEmp.Close
      Set rsEmp = Nothing
      Label11.Visible = True
      Label11 = " ! ÊãÊ ÇáÅÖÇÝÉ ÈäÌÇÍ "
   End If
End Sub

【问题讨论】:

  • 看起来tablebooks 没有名为empcode 的列。 (或者,它是使用双引号列名创建的,例如 "empcode""empCode" - 如果是这样,您必须以完全相同的方式引用它,包括大小写和双引号。)
  • 是的,我相信它正在查看的您的桌子没有它。另外作为一些友好的建议,这段代码很容易受到 SQL 注入攻击。我建议使用参数集合来提供 Text1.Text 的值,以防有人偷偷摸摸。
  • 这将非常容易受到 sql 注入攻击。
  • 此外,链接ufile.io/lzpuj 不起作用。

标签: oracle vb6


【解决方案1】:

首先确保empcode 是正确的列名。

然后修复您的代码。你有两个大问题:

  1. 它非常容易受到 Sql 注入攻击。
  2. 它会无缘无故地尝试在 ELSE 块中的同一连接上重新打开同一命令。

#1 的确切修复取决于您使用的提供商(Ole 与 Odbc),但此链接可能会有所帮助:

Call a parameterized Oracle query from ADODB in Classic ASP

对于#2,这要好一些:

Dim connEmp As ADODB.Connection
Dim rsEmp As ADODB.Recordset

Private Sub Command1_Click()
   Set rsEmp = New ADODB.Recordset
   'TODO: Use parameterized query here!
   rsEmp.Open "select * from tablebooks where empcode = @empcode '" & Text1.Text & "'", 
   connEmp, adOpenKeyset, adLockReadOnly, adCmdText
   If rsEmp.RecordCount <> 0 Then
      MsgBox " ! åÐÇ ÇáßÊÇÈ ãæÌæÏ ÈÇáÝÚá "
      rsEmp.Close
      Set rsEmp = Nothing
      Exit Sub
   End If

   rsEmp.AddNew

   rsEmp!Book_no = Val(Trim(Text1.Text))
   rsEmp!Book_name = Trim(Text2.Text)
   rsEmp!Author_name = Trim(Text10.Text)
   rsEmp!Edition_no = Val(Trim(Text3.Text))
   rsEmp!Publisher_place = Trim(Text11.Text)
   rsEmp!Part_no = Val(Trim(Text5.Text))
   rsEmp!Book_cost = Trim(Text6.Text)
   rsEmp!Place_book = Trim(Text7.Text)
   rsEmp!Note = Trim(Text9.Text)

   rsEmp!Date_publishing = DTPicker1.Value
   rsEmp!Subject = Trim(Combo4.Text)
   rsEmp!State = Trim(Combo4.Text)

   rsEmp.Update
   connEmp.Execute "commit"
   rsEmp.Close
   Set rsEmp = Nothing

   Label11.Visible = True
   Label11 = " ! ÊãÊ ÇáÅÖÇÝÉ ÈäÌÇÍ "
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2018-01-22
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多