VB6和SQL - ODBC驱动程序不支持所请求的属性

时间:2015-01-15 15:30:15

标签: sql vb6 odbc basic

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

程序如下:

Seach Form

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

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

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

所有回复都表示赞赏!谢谢!

1 个答案:

答案 0 :(得分:3)

您忘记了=符号,表单为:

where field = 'string'

此代码对SQL注入攻击是开放的,如果文本框包含'个字符,则可能会发生错误。使用参数&命令对象以避免这种情况,请参阅this

相关问题