I am trying to build my own DB Class and am trying to set up my parameter
list in an array of SqlParameter objects.
In my regular code I would do something like:
*********************************************************
Dim dbCmd As SqlCommand = New SqlCommand("GetUsers", dbConn)
dbCmd.CommandType = CommandType.StoredProcedure
dbCmd.Parameters.Add("@UserID",SqlDBType.Int).value = 1
************************************************************
In this I add the the value dircectly into the .Add SqlParameter statement.
In my class, I get an error if I do the same thing and have to do the
assignment afterwords:
**************************************
Sub LoadGrid()
Dim parameters as SqlParameter() = { _
New SqlParameter("@UserID",SqlDBType.Int) }
parameters(0).value = 1
*****************************************
Is there a way to do the above line in one statement, such as:
New SqlParameter("@UserID",SqlDBType.Int).value = 1
Thanks,
Tom
tshad - 07 Dec 2007 05:03 GMT
What I get as an error message is:
Specified cast is not valid.
Thanks,
Tom
>I am trying to build my own DB Class and am trying to set up my parameter
>list in an array of SqlParameter objects.
[quoted text clipped - 27 lines]
>
> Tom
Scott Roberts - 07 Dec 2007 15:29 GMT
How about this:
dbCmd.Parameters.AddWithValue("@UserID",1)
>I am trying to build my own DB Class and am trying to set up my parameter
>list in an array of SqlParameter objects.
[quoted text clipped - 27 lines]
>
> Tom