473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Passing SqlParameter not accepting value

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).valu e = 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


Dec 7 '07 #1
2 1670
What I get as an error message is:

Specified cast is not valid.

Thanks,

Tom

"tshad" <tf*@dslextreme.comwrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
>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).valu e = 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


Dec 7 '07 #2
How about this:

dbCmd.Parameters.AddWithValue("@UserID",1)

"tshad" <tf*@dslextreme.comwrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
>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).valu e = 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

Dec 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
2
by: vengala s reddy | last post by:
i have login.aspx, login.vb, i have my stored procedures in login.vb in login.aspx <%@ Page Language="vb" src="/MyTime/com/login.vb" Inherits="Enter.MyTime"%> in login.vb Public Sub...
2
by: Martin Raychev | last post by:
Hi all, I have the following problem: I have a private method that returns a SqlDataReader. For this to work I have not to close the DB connection in the above method. I do this only to
0
by: Mike | last post by:
Hi, I am trying to insert parameters into a stored procedure using DAAB (see code at the bottom of this post). I am getting the following error: Object reference not set to an instance of an...
2
by: Simon Harvey | last post by:
Hi everyone, I'm having a really simple problem - I can't seem to insert a null value into the database. When I do it tells me that the procedure expects the parameter and that I'm not providing...
5
by: Sridhar | last post by:
Hi, I have created a web application. I have a data access dll to interact with database. I added this dll as a reference to the web application. Now let's say if I am calling a function in data...
6
by: Tim Zych | last post by:
' Declare a new parameter object Dim param() As SqlParameter = New SqlParameter(0) {} ' Set this to null and make it an InputOutput parameter param(0) = New SqlParameter("@Something, DBNull.Value)...
3
by: cmrhema | last post by:
Hi, Kindly excuse if I am posting in the wrong place. I am using Visual Studio 2008, .net framework 3.5, asp.net , c# and sql server 2005. I am supposed to pass stored procedures from client...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.