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("Get Users", dbConn)
dbCmd.CommandTy pe = CommandType.Sto redProcedure
dbCmd.Parameter s.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",SqlDBTy pe.Int) }
parameters(0).v alue = 1
*************** *************** ***********
Is there a way to do the above line in one statement, such as:
New SqlParameter("@ UserID",SqlDBTy pe.Int).value = 1
Thanks,
Tom 2 1686
What I get as an error message is:
Specified cast is not valid.
Thanks,
Tom
"tshad" <tf*@dslextreme .comwrote in message
news:ee******** ******@TK2MSFTN GP03.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("Get Users", dbConn)
dbCmd.CommandTy pe = CommandType.Sto redProcedure
dbCmd.Parameter s.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",SqlDBTy pe.Int) }
parameters(0).v alue = 1
*************** *************** ***********
Is there a way to do the above line in one statement, such as:
New SqlParameter("@ UserID",SqlDBTy pe.Int).value = 1
Thanks,
Tom
How about this:
dbCmd.Parameter s.AddWithValue( "@UserID",1 )
"tshad" <tf*@dslextreme .comwrote in message
news:ee******** ******@TK2MSFTN GP03.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("Get Users", dbConn)
dbCmd.CommandTy pe = CommandType.Sto redProcedure
dbCmd.Parameter s.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",SqlDBTy pe.Int) }
parameters(0).v alue = 1
*************** *************** ***********
Is there a way to do the above line in one statement, such as:
New SqlParameter("@ UserID",SqlDBTy pe.Int).value = 1
Thanks,
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 click a button to
determine whether the zip code is unique. If the zip code is not unique,
another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip
code is passed to the lookup form/dialog by reference. I then load a...
|
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 pass it to the Db and retrieveing data
from a stored procedure, but I can't get the hang of parameters.
I have a method where I can get the parameters passed to the sp but it
doesn't want to return any results. Here's a copy of my code:
|
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 EnterMyTime(ByVal ID As String, ByVal PWD As String)as
dataset
|
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
|
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 object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details:...
| |
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 it.
Well, I am, its just a null value!
The code is:
con.Open();
|
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 access and if it throws
exception (like cannot find stored procedure), how do I retrieve that
exception message back in the web form? In the client, I am able to catch the
exception, but the message I am getting is "Object reference not set to an...
|
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) ' Can also be
non-null, but sometimes is null
param(0).Direction = ParameterDirection.InputOutput
' But, before we begin, store a copy of the existing parameters into another
variable
Dim param2() As SqlParameter = New SqlParameter(0) {}...
|
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 to wcf service.
The WCF service should execute the stored procedure and return the result.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |