I have the following code which I'm trying to execute but it gives me an error which says
The Function is created as such
" An insufficient number of arguments were supplied for the procedure or function dbo.Function1"
VB.NET:
Public Function test(ByVal connectionString As String)
Dim sqlConnection1 As New SqlConnection(connectionString)
sqlConnection1.Open()
' Create a command object to call Function1.
Dim sqlCommand1 As New SqlCommand()
With sqlCommand1
.CommandText = "Select dbo.[Function1]()"
.CommandType = CommandType.Text
.Connection = sqlConnection1
End With
Dim sqlDataReader1 As SqlDataReader
sqlCommand1.Parameters.Add(New SqlClient.SqlParameter("@TEST", SqlDbType.NVarChar, 20))
sqlCommand1.Parameters("@TEST").Value = "TEST"
sqlCommand1.Parameters.Add(New SqlClient.SqlParameter("@VALUE", SqlDbType.NVarChar, 20))
sqlCommand1.Parameters("@VALUE").Direction = ParameterDirection.ReturnValue
sqlCommand1.Parameters("@VALUE").Value = "<NULL>"
sqlDataReader1 = sqlCommand1.ExecuteReader
sqlDataReader1.Read()
Dim strRetVal As String
strRetVal = sqlDataReader1.Item(0)
sqlDataReader1.Close()
End Function
The Function is created as such
VB.NET:
ALTER FUNCTION dbo.Function1(@TEST nvarchar(20))
RETURNS nvarchar(20)
AS
BEGIN
declare @out nvarchar(20)
set @out = 'Hello World'
RETURN @out
END
Last edited by a moderator: