Results 1 to 8 of 8

Thread: [RESOLVED] No value given for one or more required parameters

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2019
    Posts
    6

    Resolved [RESOLVED] No value given for one or more required parameters

    Hi I am currently finishing a school project I had completed implementation however when I transferred the files to my laptop one part no longer works. The code is below

    Code:
    Private Sub cmdStation_Count_Click(sender As Object, e As EventArgs) Handles cmdStation_Count.Click
            Try
                'Lines 173-176 Declare the variables required to connect to the database'
                Dim SQLReader As OleDbDataReader
                Dim connection_type As String = "Provider=Microsoft.ACE.OLEDB.12.0;"
                Dim file_location As String = "Data Source=C:\Users\ben\Documents\Computing Science\S6 Computing Science\Advanced Higher Project\Advanced Higher Project.accdb"
                Dim conn As OleDbConnection
    
                'Lines 179 and 180 Open the connection to the Database File'
                conn = New OleDbConnection(connection_type & file_location)
                conn.Open()
    
    
                'Lines 183 andd 184 Declare the variables needed for the Count Procedure'
                Dim counter As Integer = 0
                Dim station As String
    
                'Lines 188 to 190 Receive and Validate the Inputs from the User'
                Do
                    station = InputBox("Please Enter the Train Station you would like to Count the Spottings at.")
                Loop Until Len(station) >= 5 And Len(station) <= 17
    
                'Line 193 Declares the COUNT Query'
                Dim query As String = "SELECT SpotID FROM [Spottings] WHERE station ='" & station & "';"
    
                'Lines 196 to 205 Execute the Query and Display the output in List Boxes'
                Dim command As New OleDbCommand(query, conn)
                SQLReader = command.ExecuteReader()
                If SQLReader.HasRows Then
                    While SQLReader.Read
                        counter = counter + 1
                    End While
                    lstDisplayCount.Items.Add("There has been " & counter & " Spotting(s) at " & station)
                Else
                    lstDisplayCount.Items.Add("There has been No Spottings at " & station)
                End If
    
            Catch ex As Exception
                lstDisplayCount.Items.Add(ex.Message)
            End Try
        End Sub
    Once the station has been inputted the error in the title appears
    Last edited by si_the_geek; Mar 21st, 2020 at 12:46 PM. Reason: added Code tags

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: No value given for one or more required parameters

    When you post code always put it between code tags so it will keep its formatting, on the tool bar select either "VB" or "#".

    As for your problem, does the laptop have MS Access or the runtime engine installed on it? When does the error occur. On startup or sometime after?

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: No value given for one or more required parameters

    Unfortunately the error message you are getting is one that occurs for many related issues - it basically means "there is something wrong with the SQL statement and/or parameters" (with the parameters being unlikely, and in this case also irrelevant)

    In this case the SQL statement is in the variable query. I would recommend initially removing the ; from the end of the line, as it isn't needed, and removing it might fix the issue.

    If that doesn't solve it, to find out what is causing the issue temporarily comment out the "Try" line, and the Catch section. Then when the error occurs, I would expect the issue to occur on the ExecuteReader() line. Add the query variable as a Watch to make sure that it contains something valid. If you can't spot the issue yourself, copy+paste the value here from the Watch window.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2019
    Posts
    6

    Re: No value given for one or more required parameters

    Quote Originally Posted by wes4dbt View Post
    When you post code always put it between code tags so it will keep its formatting, on the tool bar select either "VB" or "#".

    As for your problem, does the laptop have MS Access or the runtime engine installed on it? When does the error occur. On startup or sometime after?
    Yeah it has MS Access installed. The error occurs once the station has been entered into the input box and Ok is clicked

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2019
    Posts
    6

    Re: No value given for one or more required parameters

    Quote Originally Posted by si_the_geek View Post
    Unfortunately the error message you are getting is one that occurs for many related issues - it basically means "there is something wrong with the SQL statement and/or parameters" (with the parameters being unlikely, and in this case also irrelevant)

    In this case the SQL statement is in the variable query. I would recommend initially removing the ; from the end of the line, as it isn't needed, and removing it might fix the issue.

    If that doesn't solve it, to find out what is causing the issue temporarily comment out the "Try" line, and the Catch section. Then when the error occurs, I would expect the issue to occur on the ExecuteReader() line. Add the query variable as a Watch to make sure that it contains something valid. If you can't spot the issue yourself, copy+paste the value here from the Watch window.
    Name:  Try.jpg
Views: 4781
Size:  22.5 KB
    That's what appears I'm not too sure what it means

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: No value given for one or more required parameters

    When the exception occurs, take a look at command.CommandText. Paste the contents of that variable into a reply so that we can see it.

    Something is wrong with that commandtext, though exactly what it is can be pretty hard to spot. Make sure that all of the fields and tables are correct and spelled correctly.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2019
    Posts
    6

    Re: No value given for one or more required parameters

    Quote Originally Posted by Shaggy Hiker View Post
    When the exception occurs, take a look at command.CommandText. Paste the contents of that variable into a reply so that we can see it.

    Something is wrong with that commandtext, though exactly what it is can be pretty hard to spot. Make sure that all of the fields and tables are correct and spelled correctly.
    Thank you so much! I’ve just realised I’ve made a very basic silly mistake regarding a field name. So sorry for wasting your time. Thanks very much you may have just saved me from not passing an exam. Your help is very much appreciated.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: No value given for one or more required parameters

    Please use the Thread Tools menu to mark the thread Resolved. That way, people won't open it and read each post, only to discover that the issue is resolved and help is no longer required.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width