Microsoft KB Archive/105171: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
Line 84: Line 84:
<li><p>Add the following code to the Command1 Click event procedure:</p>
<li><p>Add the following code to the Command1 Click event procedure:</p>
<pre class="codesample">  Sub Command1_Click ()
<pre class="codesample">  Sub Command1_Click ()
       data1.RecordSource = &quot;Select * from authors where author = 4&quot;
       data1.RecordSource = "Select * from authors where author = 4"
       data1.Refresh        ' This gives the type mismatch error
       data1.Refresh        ' This gives the type mismatch error
   End Sub
   End Sub
Line 90: Line 90:
                         </pre>
                         </pre>
<p>NOTE: If you change the SQL query to the following, you will receive the 3061 error (1 parameter expected but only 0 were supplied):</p>
<p>NOTE: If you change the SQL query to the following, you will receive the 3061 error (1 parameter expected but only 0 were supplied):</p>
<pre class="codesample">      data1.RecordSource = &quot;Select * from authors where author = brown&quot;
<pre class="codesample">      data1.RecordSource = "Select * from authors where author = brown"


                         </pre>
                         </pre>
<p>The following query corrects the SQL syntax. It should work correctly without giving an error:</p>
<p>The following query corrects the SQL syntax. It should work correctly without giving an error:</p>
<pre class="codesample">      data1.RecordSource = &quot;Select * from authors where author = 'brown'&quot;
<pre class="codesample">      data1.RecordSource = "Select * from authors where author = 'brown'"


                         </pre></li>
                         </pre></li>
Line 101: Line 101:
       Dim db As database
       Dim db As database
       Dim ds As dynaset
       Dim ds As dynaset
       Set db = OpenDatabase(&quot;C:\VB\BIBLIO.MDB&quot;)
       Set db = OpenDatabase("C:\VB\BIBLIO.MDB")
       sqlquery1$ = &quot;Select * from authors where author = 4&quot;
       sqlquery1$ = "Select * from authors where author = 4"
       Set ds = db.CreateDynaset(sqlquery1$) 'Gives type mismatch error
       Set ds = db.CreateDynaset(sqlquery1$) 'Gives type mismatch error
   End Sub
   End Sub
Line 108: Line 108:
                         </pre>
                         </pre>
<p>NOTE: If you change the SQL query to the following, you will receive the 3061 error (1 parameter expected but only 0 were supplied):</p>
<p>NOTE: If you change the SQL query to the following, you will receive the 3061 error (1 parameter expected but only 0 were supplied):</p>
<pre class="codesample">      sqlquery1$ = &quot;Select * from authors where author = brown&quot;
<pre class="codesample">      sqlquery1$ = "Select * from authors where author = brown"


                         </pre>
                         </pre>
<p>The following query corrects the SQL syntax. It should work correctly without giving an error:</p>
<p>The following query corrects the SQL syntax. It should work correctly without giving an error:</p>
<pre class="codesample">      sqlquery1$ = &quot;Select * from authors where author = 'brown'&quot;
<pre class="codesample">      sqlquery1$ = "Select * from authors where author = 'brown'"


                         </pre></li>
                         </pre></li>

Revision as of 10:09, 20 July 2020

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