The information in this article applies to:
- Microsoft Visual Basic programming system for Windows, version 3.0
SYMPTOMS
Incorrect SQL syntax can cause either of the following error messages:
- Type Mismatch (Error 13)
- 1 parameter expected but only 0 were supplied (Error 3061)
You may receive one of the above errors with a data access object method
that contains a SQL statement, or when using the Refresh method on a Data
control that has its RecordSource property set to a SQL statement.
CAUSE
The SQL syntax is incorrect.
RESOLUTION
Correct the SQL syntax. See the examples in the Steps to Reproduce Behavior
section below.
MORE INFORMATION
Steps to Reproduce Behavior
- Start a new project in Visual Basic. Form1 is created by default.
- Add a data control (Data1) and two command buttons (Command1 and
Command2) to Form1.
- Set the following properties for the Data1 control:
Control Property Value Set
------------------------------------------------------
Data1 DataBaseName C:\VB\BIBLIO.MDB
Data1 RecordSource Authors
- Add the following code to the Command1 Click event procedure:
Sub Command1_Click ()
data1.RecordSource = "Select * from authors where author = 4"
data1.Refresh ' This gives the type mismatch error
End Sub
NOTE: If you change the SQL query to the following, you will receive
the 3061 error (1 parameter expected but only 0 were supplied):
data1.RecordSource = "Select * from authors where author = brown"
The following query corrects the SQL syntax. It should work correctly
without giving an error:
data1.RecordSource = "Select * from authors where author = 'brown'"
- Add the following code to the Command2 Click event procedure:
Sub Command2_Click ()
Dim db As database
Dim ds As dynaset
Set db = OpenDatabase("C:\VB\BIBLIO.MDB")
sqlquery1$ = "Select * from authors where author = 4"
Set ds = db.CreateDynaset(sqlquery1$) 'Gives type mismatch error
End Sub
NOTE: If you change the SQL query to the following, you will receive
the 3061 error (1 parameter expected but only 0 were supplied):
sqlquery1$ = "Select * from authors where author = brown"
The following query corrects the SQL syntax. It should work correctly
without giving an error:
sqlquery1$ = "Select * from authors where author = 'brown'"
- From the Run menu, choose Start (ALT, R, S) or press the F5 key to run
the program. Click the Command1 button to get the error. Then restart
the program, and click the Command2 button to get the error.
|