I'm completely new to Powershell so i'm a little confused about how to call a SQL procedure that takes parameters. I have opened a connection to my database successfully and i've managed to get a procedure that doesn't take parameters to work so I know that the connection is fine.
The code to add a parameter and run the query is below:
$dateToUse = Get-Date -f yyyy/MM/dd
$MysqlQuery.CommandText = "GetJourneyByDepartureDate"
$MysqlQuery.Parameters.AddWithValue("_departureDate", $dateToUse)
$queryOutput = $MysqlQuery.ExecuteReader()
Whenever I try and run my script I get an error saying
Incorrect number of arguments for PROCEDURE dbo.GetJourneyByDepartureDate; expected 1, got 0
I've had a look around trying to find a solution but I don't understand enough about Powershell to know what solutions might be correct.
Also I am unable to post the SQL query but I have managed to run the procedure many times by just running the query in HeidiSQL passing the arguement manually
EDIT:
I've now changed my code slightly, it now looks like this:
$MysqlQuery.CommandText = "GetJourneyByDepartureDate"
$MysqlQuery.Parameters.Add("@_departureDate", [System.Data.SqlDbType]::Date) | out-Null
$MysqlQuery.Parameters['@_departureDate'].Value = $dateToUse
$parameterValue = $MysqlQuery.Parameters['@_departureDate'].value
Write-Host -ForegroundColor Cyan -Object "$parameterValue";
$queryOutput = $MysqlQuery.ExecuteReader()
I'm getting the $dateToUse value output on the console in the Write-Host line but i'm still getting the same Incorrect number of arguments error as before. SP is declared as below:
CREATE PROCEDURE `GetJourneyByDepartureDate`(IN `_departureDate` DATE) READS SQL DATA
$MysqlQuery.Parameters.AddWithValue("@departureDate", $dateToUse).