Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Passing SqlParameter not accepting value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 07 Dec 2007 04:55 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.