【问题标题】:VB6 and SQL - ODBC driver does not support the requested propertiesVB6 和 SQL - ODBC 驱动程序不支持请求的属性
【发布时间】:2023-03-24 07:20:02
【问题描述】:

我正在为一个学校项目开发一个程序,该项目基于 Youtube 上的“如何使用带有 VB6 的 SQL Server(包括选择和插入)”视频。

程序如下所示:

单击单选按钮会启用与其相邻的文本框并禁用其余文本框(大文本框除外。然后在“搜索”按钮内嵌入以下代码:

Dim aConnection As New ADODB.Connection
Dim aRecSet As New ADODB.Recordset

Private Sub cmdSearch_Click()
If txtStuNum.Enabled = True Then
    aRecSet.Open "select * from studentTable where studentNumber'" & txtDisplay.Text & "'", aConnection, adOpenKeyset
ElseIf txtName.Enabled = True Then
    aRecSet.Open "select * from studentTable where Name'" & txtDisplay.Text & "'", aConnection, adOpenKeyset
ElseIf txtGrade.Enabled = True Then
    aRecSet.Open "select * from studentTable where Grade'" & txtDisplay.Text & "'", aConnection, adOpenKeyset
ElseIf txtSection.Enabled = True Then
    aRecSet.Open "select * from studentTable where section'" & txtDisplay.Text & "'", aConnection, adOpenKeyset
End If

End Sub

当我按下搜索按钮时,会弹出:

感谢所有回复!谢谢!

【问题讨论】:

    标签: sql vb6 odbc basic


    【解决方案1】:

    您忘记了= 符号,格式为:

    where field = 'string'

    此代码对 SQL 注入攻击开放,如果文本框包含 ' 字符,可能会发生坏事。使用 Parameter & Command 对象来避免这种情况,请参阅this

    【讨论】:

    • 您好,感谢您的回答!但是,当我添加“=”时,它仍然显示相同的错误。关于 ' ,我个人认为没关系,因为我不希望任何人使用该特定字符。这个问题还有更多可能的答案吗?谢谢!
    • 尝试删除adOpenKeySet,改为:aRecSet.Open "select * from studentTable where section ='" & txtDisplay.Text & "'", aConnection, adOpenStatic, adLockReadOnly
    • ' 问题应该得到解决,它被称为 SQL 注入缺陷,可能允许恶意用户从您的数据库中删除数据; stackoverflow.com/questions/601300/what-is-sql-injection
    • 至少您可以通过将' 转义为 2 x ' 来手动防止这种情况:section ='" & replace$(txtDisplay, "'", "''").Text &“'”`
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 1970-01-01
    • 2022-08-19
    相关资源
    最近更新 更多