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

What does VB/SQL Server want for a parameter name?

Greetings!

I have a SQL Server stored procedure that takes one parameter, named @key.
I am trying to run that stored procedure from a VB app. When I create a
Parameter object and give it the name "key", I get an error message that
says "key is not a parameter for procedure sp_get_active_holdings". When I
name the parameter "@key", I get a message that says "Procedure
'sp_get_active_holdings' expects parameter '@key', which was not supplied."

Huh?

It looks like VB is complaining first that "key" is incorrect, and then SQL
is complaining that "@key" is incorrect! What do I have to do? It's a
dinky little stored procedure that could be done just as well in the VB
code, but I'd really like to have all DB-related stuff in the DB.

Here's the procedure:

ALTER PROCEDURE dbo.sp_get_active_holdings (@key INT)
AS
SELECT Name, Symbol, Quantity, Execute_price, IsLong
FROM Holdings
WHERE Covered = 0 AND Portfolio_fk = @key
ORDER BY Symbol;

Here's the VB code:

Public Sub Open(ByVal number As Integer)
m_connection = gDB
Try
If gDB.State = ConnectionState.Closed Then
m_connection.Open()
End If

dcmdData.Connection = gDB
daData.SelectCommand = dcmdData
Dim dtData As New dsPortfolio.PortfolioDataDataTable
daData.Fill(dtData)
m_drowData = dtData.Rows(0)
Dim daActiveHolding As New SqlDataAdapter
Dim dcmdActiveHolding As New SqlCommand
Dim pKeyParam As New SqlParameter
Dim pReturnParam As New SqlParameter
pReturnParam.ParameterName = "@RETURN_VALUE"
pReturnParam.Direction = ParameterDirection.ReturnValue
dcmdActiveHolding.Parameters.Add(pReturnParam)
pKeyParam.ParameterName = "@key"
pKeyParam.SqlDbType = SqlDbType.Int
pKeyParam.Direction = ParameterDirection.Input
dcmdActiveHolding.Connection = gDB
dcmdActiveHolding.CommandType = CommandType.StoredProcedure
dcmdActiveHolding.CommandText = "sp_get_active_holdings"
dcmdActiveHolding.Connection = m_connection
dcmdActiveHolding.Parameters.Add(pKeyParam)
daActiveHolding.SelectCommand = dcmdActiveHolding
m_activeHoldings = New dsPortfolio.ActiveHoldingsDataTable
daActiveHolding.SelectCommand = dcmdActiveHolding
daActiveHolding.Fill(m_activeHoldings)

Catch e As SqlException
MessageBox.Show("Error when opening database: " & vbCrLf & _
e.Message)
End Try
End Sub

Thanks very much!

Rob
Nov 21 '05 #1
1 2619
Hi Rob,

It doesn't look like you are assigning the pKeyParam a value. Something
like pKeyParam.Value = 5. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Rob Richardson" <th*****@n2net.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Greetings!

I have a SQL Server stored procedure that takes one parameter, named @key.
I am trying to run that stored procedure from a VB app. When I create a
Parameter object and give it the name "key", I get an error message that
says "key is not a parameter for procedure sp_get_active_holdings". When I name the parameter "@key", I get a message that says "Procedure
'sp_get_active_holdings' expects parameter '@key', which was not supplied."
Huh?

It looks like VB is complaining first that "key" is incorrect, and then SQL is complaining that "@key" is incorrect! What do I have to do? It's a
dinky little stored procedure that could be done just as well in the VB
code, but I'd really like to have all DB-related stuff in the DB.

Here's the procedure:

ALTER PROCEDURE dbo.sp_get_active_holdings (@key INT)
AS
SELECT Name, Symbol, Quantity, Execute_price, IsLong
FROM Holdings
WHERE Covered = 0 AND Portfolio_fk = @key
ORDER BY Symbol;

Here's the VB code:

Public Sub Open(ByVal number As Integer)
m_connection = gDB
Try
If gDB.State = ConnectionState.Closed Then
m_connection.Open()
End If

dcmdData.Connection = gDB
daData.SelectCommand = dcmdData
Dim dtData As New dsPortfolio.PortfolioDataDataTable
daData.Fill(dtData)
m_drowData = dtData.Rows(0)
Dim daActiveHolding As New SqlDataAdapter
Dim dcmdActiveHolding As New SqlCommand
Dim pKeyParam As New SqlParameter
Dim pReturnParam As New SqlParameter
pReturnParam.ParameterName = "@RETURN_VALUE"
pReturnParam.Direction = ParameterDirection.ReturnValue
dcmdActiveHolding.Parameters.Add(pReturnParam)
pKeyParam.ParameterName = "@key"
pKeyParam.SqlDbType = SqlDbType.Int
pKeyParam.Direction = ParameterDirection.Input
dcmdActiveHolding.Connection = gDB
dcmdActiveHolding.CommandType = CommandType.StoredProcedure
dcmdActiveHolding.CommandText = "sp_get_active_holdings"
dcmdActiveHolding.Connection = m_connection
dcmdActiveHolding.Parameters.Add(pKeyParam)
daActiveHolding.SelectCommand = dcmdActiveHolding
m_activeHoldings = New dsPortfolio.ActiveHoldingsDataTable
daActiveHolding.SelectCommand = dcmdActiveHolding
daActiveHolding.Fill(m_activeHoldings)

Catch e As SqlException
MessageBox.Show("Error when opening database: " & vbCrLf & _
e.Message)
End Try
End Sub

Thanks very much!

Rob

Nov 21 '05 #2

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

Similar topics

26
by: Steven Bethard | last post by:
I thought it might be useful to put the recent lambda threads into perspective a bit. I was wondering what lambda gets used for in "real" code, so I grepped my Python Lib directory. Here are some...
0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
8
by: DanB | last post by:
This is probably soooo simple but I can't seem to get it. I have a text file that I want users to download via a web page. I want the file to be saved to a default folder (or one that they...
4
by: nicholas | last post by:
Weird thing: Got an aspx page with a button and an associated code in VB.net. On my testing server the page works fine. On the old hosters server the page worked fine too. But now, at the new...
5
by: Amelyan | last post by:
I am struggling here trying to determine what is a good programming practice as far as referencing your URLs. When you use Response.Redirect, do you use 1) Hard-coded string --...
3
by: Jordan | last post by:
I am dynamically inserting an html <input> tag as text (equivalent of an image button) into a page via a Literal control. Something like this gets inserted: <input type="image"...
7
by: ÀÏÆÅ»³ÔÐ5¸öÔ | last post by:
I want use dropdownlist contral in gridview but have trouble now mycode here: i'm very sorry for my poor english <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"...
11
by: pamelafluente | last post by:
Hi I am executing some simple sample code: Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text, Me.OleDbConnection) Dim OleDbParameter As OleDbParameter =...
0
by: Steve | last post by:
I have a gridview which uses an objectdatasource for its select and delete. The delete command uses the function below. The delete itself works but the extra logic which requires parameters...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.