-
Mar 21st, 2020, 12:35 PM
#1
Thread Starter
New Member
[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
-
Mar 21st, 2020, 12:47 PM
#2
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?
-
Mar 21st, 2020, 12:55 PM
#3
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.
-
Mar 21st, 2020, 01:50 PM
#4
Thread Starter
New Member
Re: No value given for one or more required parameters
Originally Posted by wes4dbt
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
-
Mar 21st, 2020, 03:42 PM
#5
Thread Starter
New Member
Re: No value given for one or more required parameters
Originally Posted by si_the_geek
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.
That's what appears I'm not too sure what it means
-
Mar 21st, 2020, 03:46 PM
#6
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
-
Mar 21st, 2020, 03:54 PM
#7
Thread Starter
New Member
Re: No value given for one or more required parameters
Originally Posted by Shaggy Hiker
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.
-
Mar 21st, 2020, 10:03 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|