Microsoft KB Archive/105171

From BetaArchive Wiki

Article ID: 105171

Article Last Modified on 1/8/2003



APPLIES TO

  • Microsoft Visual Basic 3.0 Professional Edition



This article was previously published under Q105171

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

  1. Start a new project in Visual Basic. Form1 is created by default.
  2. Add a data control (Data1) and two command buttons (Command1 and Command2) to Form1.
  3. Set the following properties for the Data1 control:

       Control           Property           Value Set
       ------------------------------------------------------
       Data1             DataBaseName       C:\VB\BIBLIO.MDB
       Data1             RecordSource       Authors
    
                            
  4. 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'"
    
                            
  5. 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'"
    
                            
  6. 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.



Additional query words: 3.00

Keywords: kbprb KB105171