This is driving me nuts!
In a VB.Net program I have an SQL command object to call a stored procedure as follows:
With SQLCmdTSUpdate
.CommandText = "xxxxx_xxxxxxx_xxxxx_xxxxxx"
.CommandType = CommandType.StoredProcedure
.Connection = conn
.Parameters.Add(New SqlClient.SqlParameter("@p_employee_login";, SqlDbType.VarChar, 10, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_start_date", SqlDbType.DateTime, 8, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, Now))
.Parameters.Add(New SqlClient.SqlParameter("@p_ts_job_contracts", SqlDbType.VarChar, 220, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_mondays", SqlDbType.VarChar, 100, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_tuesdays", SqlDbType.VarChar, 100, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_wednesdays", SqlDbType.VarChar, 100, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_thursdays", SqlDbType.VarChar, 100, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_fridays", SqlDbType.VarChar, 100, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_saturdays", SqlDbType.VarChar, 100, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_sundays", SqlDbType.VarChar, 100, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_ts_categories", SqlDbType.VarChar, 140, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_disb_uniques", SqlDbType.VarChar, 220, ParameterDirection.InputOutput, False, 30, 0, "";, DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_disb_actions", SqlDbType.VarChar, 40, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_disb_dates", SqlDbType.VarChar, 220, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_disb_job_contracts", SqlDbType.VarChar, 220, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_claim_values", SqlDbType.VarChar, 160, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_vat_elements", SqlDbType.VarChar, 160, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_claim_backs", SqlDbType.VarChar, 40, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_disb_categories", SqlDbType.VarChar, 140, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
.Parameters.Add(New SqlClient.SqlParameter("@p_details", SqlDbType.VarChar, 1020, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, ""))
End With
Only one of the parameters is inputoutput
Having set the input parameters and then using:
SQLCmdTSUpdate.ExecuteNonQuery()
The SQL stored procedure is executed fine and has the desired results (and returns some value in the inputoutput parameter as expected). However the stored procedure uses the return value to notify whether the actions within the sp were done OK, so I need to access this return value.
As soon as I add the extra parameter as the first parameter as follows:
.Parameters.Add(New SqlClient.SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue))
and then use the ExecuteNonQuery, I get an error about too many parameters
It is as if the dot net framework is not recognising that the extra parameter is for the return value.
Although I could add another output parameter to return the return code, the stored procedures in question have been used for years in VB6 programs with return values with no problems and I have no desire to re-write the sps just because VB.Net is being used.
Any pointers would be hugely appreciated. Thanks