473,396 Members | 1,836 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,396 software developers and data experts.

Calling a parameterized stored proc with adtaper or command obj

Help! I'm trying to call a parameterized stored proc in ASP.NET in VB. I am
creating a command object and creating a parametr list, and assigning a value
from a session variable (this is working) so that I can sen in the value as a
parameter. When I try to use the adapter's fill command to fill the data set,
it get a error tellig me that I am not giving the stored procedure the
parameter that it expects, even though I am! I've looked through some of my
old code that works, and it still doesn't seem to make sense.

Here is what I have:

If Not Page.IsPostBack Then
contactID = Session("ContactID") 'This is a valid value!
vendorID = Session("VendorID") ' As is this

Dim Connection As New
SqlClient.SqlConnection(System.Configuration.Confi gurationSettings.AppSettings("PurchaseDB"))
MyComm = New SqlClient.SqlCommand
MyComm.Connection = Connection

MyComm.Parameters.Add(New SqlClient.SqlParameter("@Contact_ID",
SqlDbType.Int, 4)).Direction = ParameterDirection.Input
MyComm.Parameters("@Contact_ID").Value = contactID

MyComm.CommandType = CommandType.StoredProcedure
MyComm.CommandText = "spGetContact"

myAdapter = New SqlClient.SqlDataAdapter(MyComm.CommandText,
Connection)
dsOne = New System.Data.DataSet

Connection.Open()
myAdapter.Fill(dsOne) ' It crahses here every time.
Connection.Close()

Am I missing something? Does this not work with an adapter?

I've also tried just using the MyComm.ExecuteNonQuery(), but then I don't
know how to get at the record set that the stroed proc returns. I have about
12 different item that get returned and I thought that a data set would be
best here, but It doesn't think it's getting the parameter values for some
reason.
Nov 18 '05 #1
1 1710
If the Session("ContactID") is nothing then the parameter would be passed in
as Default and must be handled in the stored proc - if not, you will get the
parameter not found error.

You may try this:

If Not Page.IsPostBack Then
vendorID = Session("VendorID") ' As is this

Dim Connection As New
SqlClient.SqlConnection(System.Configuration.Confi gurationSettings.AppSettin
gs("PurchaseDB"))
MyComm = New SqlClient.SqlCommand
MyComm.Connection = Connection

MyComm.Parameters.Add("@Contact_ID", Session("ContactID"))
' You may even try hardcoded values to verify if the stored proc works:
' MyComm.Parameters.Add("@Contact_ID", 45)

MyComm.CommandType = CommandType.StoredProcedure
MyComm.CommandText = "spGetContact"

myAdapter = New SqlClient.SqlDataAdapter(MyComm.CommandText,
Connection)
dsOne = New System.Data.DataSet

Connection.Open()
myAdapter.Fill(dsOne) ' It crahses here every time.
Connection.Close()
Sekhar.

"Eric Land" <Eric La**@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
Help! I'm trying to call a parameterized stored proc in ASP.NET in VB. I am creating a command object and creating a parametr list, and assigning a value from a session variable (this is working) so that I can sen in the value as a parameter. When I try to use the adapter's fill command to fill the data set, it get a error tellig me that I am not giving the stored procedure the
parameter that it expects, even though I am! I've looked through some of my old code that works, and it still doesn't seem to make sense.

Here is what I have:

If Not Page.IsPostBack Then
contactID = Session("ContactID") 'This is a valid value!
vendorID = Session("VendorID") ' As is this

Dim Connection As New
SqlClient.SqlConnection(System.Configuration.Confi gurationSettings.AppSettin
gs("PurchaseDB")) MyComm = New SqlClient.SqlCommand
MyComm.Connection = Connection

MyComm.Parameters.Add(New SqlClient.SqlParameter("@Contact_ID", SqlDbType.Int, 4)).Direction = ParameterDirection.Input
MyComm.Parameters("@Contact_ID").Value = contactID

MyComm.CommandType = CommandType.StoredProcedure
MyComm.CommandText = "spGetContact"

myAdapter = New SqlClient.SqlDataAdapter(MyComm.CommandText,
Connection)
dsOne = New System.Data.DataSet

Connection.Open()
myAdapter.Fill(dsOne) ' It crahses here every time.
Connection.Close()

Am I missing something? Does this not work with an adapter?

I've also tried just using the MyComm.ExecuteNonQuery(), but then I don't
know how to get at the record set that the stroed proc returns. I have about 12 different item that get returned and I thought that a data set would be
best here, but It doesn't think it's getting the parameter values for some
reason.

Nov 18 '05 #2

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

Similar topics

6
by: dw | last post by:
Hello all, I'm having a dickens of a time calling a stored procedure on a connection. Every time I do, it generates an error "Arguments are of the wrong type, are out of acceptable range, or are in...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
5
by: adolf garlic | last post by:
Im trying to return xml from sql. The xml is made up of different fragments, some using FOR XML ... syntax. The result is a valid xml doc. There is a working stored proc that returns the xml In...
0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
5
by: Zlatko Matić | last post by:
Hello. How can I call some functions on MSDE when working in .mdb ? Especially in-line functions which are similar to stored procedures. How can I use MSDE in-line functions as recordsource for...
5
by: David Davis | last post by:
I have the following stored procedure in an sql database ------------------------------------ CREATE PROCEDURE zspQuoteSummary @dStart DateTime, @dEnd DateTime AS SELECT qtmast.fstatus,...
0
by: Tom | last post by:
Looking for some help with stored procedure call issues. Conceptually, I need to pass a data structure as the sole parameter to the Oracle stored procedure. Sounds simple enough....but how? ...
1
by: Psychobudgie | last post by:
Hi, I have written a stored procedure which includes a DATEPART command, i.e. DATEPART(weekday, <date>) The result when ran from SQL Query Analyser is as expected . i.e. Sunday returns 1,...
14
by: krishna1412 | last post by:
Currently i am working in a project of report generation in MS ACCESS. The tables are in sql server 2000. I have to write stored proc in ms access. Illustration: I am having a stored proc...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.