I have the following ASP.NET (VB) code below.
My goal is to get the output of a stored proc that accepts 1 parameter and store that info
into a data table:
Dim strConnection1 As String = System.Configuration.ConfigurationManager.AppSettings("Rdf2012")
Dim conn1 As System.Data.SqlClient.SqlConnection
conn1 = New System.Data.SqlClient.SqlConnection(strConnection1)
Dim cmd1 As New SqlCommand
Dim prm1 As New SqlParameter
Dim dtDataTable1 As DataTable
cmd1.Connection = conn1
cmd1.CommandText = "usp_GetDetails"
cmd1.CommandType = CommandType.StoredProcedure
prm1 = cmd1.Parameters.Add(strProgramID, SqlDbType.VarChar, 50)
prm1.Direction = ParameterDirection.Input
conn1.Open()
Dim dataAdapter As New SqlDataAdapter
dataAdapter.SelectCommand = cmd1
Dim ds1 As New DataSet
dataAdapter.Fill(ds1)
conn1.Close()
dtDataTable1 = ds1.Tables("Table1")
Program stops at
dataAdapter.Fill(ds1) and says:
@1012952-4403 is not a parameter for procedure usp_GetDetails
This is what the stored proc looks like:
ALTER PROCEDURE [dbo].[usp_GetDetails]
@ProId VARCHAR(20) = NULL
AS
You need to do
instead of
Direction will be assumed to be input unless otherwise specified.