Chester Tuason
Chester Tuason

Reputation: 1

VB6 and SQL - ODBC driver does not support the requested properties

I am developing a program for a school project that is kind of based on the "How to Use SQL Server with VB6 (inc. select & insert)" video on Youtube.

The program looks like this:

Seach Form

Clicking a radio button enables the textbox adjacent to it and disables the rest (except for the big textbox. Then inside the Search button, the following code is embedded:

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

And when I press the search button, this pops up: Error Message

All responses are appreciated! Thanks!

Upvotes: 0

Views: 10148

Answers (1)

Alex K.
Alex K.

Reputation: 175926

You forgot the = sign, the form is:

where field = 'string'

This code is open to SQL Injection attacks, if a textbox contained a ' character bad things can happen. Use Parameter & Command objects to avoid this, See this.

Upvotes: 3

Related Questions