473,405 Members | 2,141 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.

PARAMETER TO Stored Procedure

hI,
i'M TRTYING TO PASS PARAMETER TO A SP.BUT GETTING "OUT OF RANGE ERROR ERROR
FOLLOWING IS THE CODE:
Dim conDG As SqlClient.SqlConnection
Dim cmdDG As SqlClient.SqlCommand
Dim drDG As SqlClient.SqlDataReader
Dim dtDueYear As String
Dim sqldataAdapter1 As SqlClient.SqlDataAdapter
dtDueYear = Trim(txtYear.Text)
' If (IsDate(dtDueYear) = True) Then
conDG = New
SqlClient.SqlConnection("Server=SQLDB;UID=PWD;pwd= ;Database=SampleDB")
cmdDG = New SqlClient.SqlCommand("USE testdb EXEC
sp_CrossTabTask
'Task_T','Initial_CH','Initials','Convert(char(3), Due_Date_DT)','DATEPART(YYYY,Due_Date_DT)'", conDG).Parameters(@dDate).Value ' = trim(dtDueYear.text)

where dDate is the parameter I have declared int the Stored procedure.

Thanks in advance..
Mar 28 '06 #1
6 3685
1. Specify the database that you want to operate against in the connection
string, rather than in the command.
2. In the command, specify only the stored proc name.
3. Set the command to be of CommandType = StoredProc.
4. Set each parameter for the command.
5. Execute the command.

Your current command string is executing the stored proc directly, and
passes the parameters to it.

Apart from that, your parameter @dDate is not in the parameters collection,
thus the out of range error.

"gurvar" <gu****@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
hI,
i'M TRTYING TO PASS PARAMETER TO A SP.BUT GETTING "OUT OF RANGE ERROR
ERROR
FOLLOWING IS THE CODE:
Dim conDG As SqlClient.SqlConnection
Dim cmdDG As SqlClient.SqlCommand
Dim drDG As SqlClient.SqlDataReader
Dim dtDueYear As String
Dim sqldataAdapter1 As SqlClient.SqlDataAdapter
dtDueYear = Trim(txtYear.Text)
' If (IsDate(dtDueYear) = True) Then
conDG = New
SqlClient.SqlConnection("Server=SQLDB;UID=PWD;pwd= ;Database=SampleDB")
cmdDG = New SqlClient.SqlCommand("USE testdb EXEC
sp_CrossTabTask
'Task_T','Initial_CH','Initials','Convert(char(3), Due_Date_DT)','DATEPART(YYYY,Due_Date_DT)'",
conDG).Parameters(@dDate).Value ' = trim(dtDueYear.text)

where dDate is the parameter I have declared int the Stored procedure.

Thanks in advance..

Mar 29 '06 #2
Gurvar,

Have a look at this sample on our website. That you use a Stored Procedure
is completely inrelevant for programming with AdoNet. It only tells that you
have the command on the server.

http://www.vb-tips.com/default.aspx?...6-7139b8970071

I hope this helps,

Cor
Mar 29 '06 #3
Thanks for a very informative link. I was able to do the con/cmd.
but I'm stuck at the Add parameter part.
Following is the error I'm getting:

The SqlParameterCollection only accepts non-null SqlParameter type objects,
not String objects.
-------------------------
cmdDG = New
SqlClient.SqlCommand("sp_CrossTabTask('Task_T','mo nth(Due_Date_DT)','MonthInitials','Initial_CH','CO NVERT(char(3),Due_Date_DT)'

cmdDG.CommandType = CommandType.StoredProcedure
cmdDG.Parameters.Add("@table", sysname) ' There is no sysname for dbType
cmdDG.Parameters.Add("@onrows", "month(Due_Date_DT)") '
cmdDG.Parameters.Add("@onrowsalias", "MonthsInitials")
cmdDG.Parameters.Add("@oncols", Trim(txtYear.Text).tostring)
sp_CrossTabTask
'Task_T','month(Due_Date_DT)','MonthsInitials','Co nvert(char93),Due_Date)DT =
'2003') --works on SQL server

@table AS sysname, --Table to crosstab
@onrows AS nvarchar(128), --Grouping key values(on rows)
@onrowsalias AS sysname = NULL, --Alias for grouping column
@oncols AS nvarchar(128), --Destination columns (on columns)
@Date AS nvarchar(128),
@sumcol AS sysname = NULL --Data cells

Thanks,
Sangeetha
"Cor Ligthert [MVP]" wrote:
Gurvar,

Have a look at this sample on our website. That you use a Stored Procedure
is completely inrelevant for programming with AdoNet. It only tells that you
have the command on the server.

http://www.vb-tips.com/default.aspx?...6-7139b8970071

I hope this helps,

Cor

Mar 30 '06 #4
Try something like this:

cmdDG = New SqlClient.SqlCommand("sp_CrossTabTask")
cmdDG.CommandType = CommandType.StoredProcedure

cmdDG.Parameters.Add("@table", value_of_table)
cmdDG.Parameters.Add("@onrows", whatever_here)
cmdDG.Parameters.Add("@onrowsalias", whatever_here)
cmdDG.Parameters.Add("@oncols", whatever_here)

"gurvar" <gu****@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Thanks for a very informative link. I was able to do the con/cmd.
but I'm stuck at the Add parameter part.
Following is the error I'm getting:

The SqlParameterCollection only accepts non-null SqlParameter type
objects,
not String objects.
-------------------------
cmdDG = New
SqlClient.SqlCommand("sp_CrossTabTask('Task_T','mo nth(Due_Date_DT)','MonthInitials','Initial_CH','CO NVERT(char(3),Due_Date_DT)'

cmdDG.CommandType = CommandType.StoredProcedure
cmdDG.Parameters.Add("@table", sysname) ' There is no sysname for dbType
cmdDG.Parameters.Add("@onrows", "month(Due_Date_DT)") '
cmdDG.Parameters.Add("@onrowsalias", "MonthsInitials")
cmdDG.Parameters.Add("@oncols", Trim(txtYear.Text).tostring)
sp_CrossTabTask
'Task_T','month(Due_Date_DT)','MonthsInitials','Co nvert(char93),Due_Date)DT
=
'2003') --works on SQL server

@table AS sysname, --Table to crosstab
@onrows AS nvarchar(128), --Grouping key values(on rows)
@onrowsalias AS sysname = NULL, --Alias for grouping column
@oncols AS nvarchar(128), --Destination columns (on columns)
@Date AS nvarchar(128),
@sumcol AS sysname = NULL --Data cells

Thanks,
Sangeetha
"Cor Ligthert [MVP]" wrote:
Gurvar,

Have a look at this sample on our website. That you use a Stored
Procedure
is completely inrelevant for programming with AdoNet. It only tells that
you
have the command on the server.

http://www.vb-tips.com/default.aspx?...6-7139b8970071

I hope this helps,

Cor

Mar 30 '06 #5
Hi,
Thanks for all the help.I have come really close.
But having problem with sending the last input parameter which goes in the
WHERE clause as month(Due_Date_DT) = @ddate

I'm getting error at "GROUP". Is it because the date charecter is declared
as @ddate nvarchar(128) but assigned to a Date funtion. But sent as a string
from UI?

cmdDG.Parameters.Add("@ddate", trim(txtvalue.text))

Thanks in advance again...

"Brendan Green" wrote:
Try something like this:

cmdDG = New SqlClient.SqlCommand("sp_CrossTabTask")
cmdDG.CommandType = CommandType.StoredProcedure

cmdDG.Parameters.Add("@table", value_of_table)
cmdDG.Parameters.Add("@onrows", whatever_here)
cmdDG.Parameters.Add("@onrowsalias", whatever_here)
cmdDG.Parameters.Add("@oncols", whatever_here)

"gurvar" <gu****@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Thanks for a very informative link. I was able to do the con/cmd.
but I'm stuck at the Add parameter part.
Following is the error I'm getting:

The SqlParameterCollection only accepts non-null SqlParameter type
objects,
not String objects.
-------------------------
cmdDG = New
SqlClient.SqlCommand("sp_CrossTabTask('Task_T','mo nth(Due_Date_DT)','MonthInitials','Initial_CH','CO NVERT(char(3),Due_Date_DT)'

cmdDG.CommandType = CommandType.StoredProcedure
cmdDG.Parameters.Add("@table", sysname) ' There is no sysname for dbType
cmdDG.Parameters.Add("@onrows", "month(Due_Date_DT)") '
cmdDG.Parameters.Add("@onrowsalias", "MonthsInitials")
cmdDG.Parameters.Add("@oncols", Trim(txtYear.Text).tostring)
sp_CrossTabTask
'Task_T','month(Due_Date_DT)','MonthsInitials','Co nvert(char93),Due_Date)DT
=
'2003') --works on SQL server

@table AS sysname, --Table to crosstab
@onrows AS nvarchar(128), --Grouping key values(on rows)
@onrowsalias AS sysname = NULL, --Alias for grouping column
@oncols AS nvarchar(128), --Destination columns (on columns)
@Date AS nvarchar(128),
@sumcol AS sysname = NULL --Data cells

Thanks,
Sangeetha
"Cor Ligthert [MVP]" wrote:
Gurvar,

Have a look at this sample on our website. That you use a Stored
Procedure
is completely inrelevant for programming with AdoNet. It only tells that
you
have the command on the server.

http://www.vb-tips.com/default.aspx?...6-7139b8970071

I hope this helps,

Cor


Mar 31 '06 #6
Can you post the exact error message, along with the code for the stored
proc?

"gurvar" <gu****@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
Hi,
Thanks for all the help.I have come really close.
But having problem with sending the last input parameter which goes in the
WHERE clause as month(Due_Date_DT) = @ddate

I'm getting error at "GROUP". Is it because the date charecter is declared
as @ddate nvarchar(128) but assigned to a Date funtion. But sent as a
string
from UI?

cmdDG.Parameters.Add("@ddate", trim(txtvalue.text))

Thanks in advance again...

"Brendan Green" wrote:
Try something like this:

cmdDG = New SqlClient.SqlCommand("sp_CrossTabTask")
cmdDG.CommandType = CommandType.StoredProcedure

cmdDG.Parameters.Add("@table", value_of_table)
cmdDG.Parameters.Add("@onrows", whatever_here)
cmdDG.Parameters.Add("@onrowsalias", whatever_here)
cmdDG.Parameters.Add("@oncols", whatever_here)

"gurvar" <gu****@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
> Thanks for a very informative link. I was able to do the con/cmd.
> but I'm stuck at the Add parameter part.
> Following is the error I'm getting:
>
> The SqlParameterCollection only accepts non-null SqlParameter type
> objects,
> not String objects.
> -------------------------
> cmdDG = New
> SqlClient.SqlCommand("sp_CrossTabTask('Task_T','mo nth(Due_Date_DT)','MonthInitials','Initial_CH','CO NVERT(char(3),Due_Date_DT)'
>
> cmdDG.CommandType = CommandType.StoredProcedure
> cmdDG.Parameters.Add("@table", sysname) ' There is no sysname for
> dbType
> cmdDG.Parameters.Add("@onrows", "month(Due_Date_DT)") '
> cmdDG.Parameters.Add("@onrowsalias", "MonthsInitials")
> cmdDG.Parameters.Add("@oncols", Trim(txtYear.Text).tostring)
>
>
> sp_CrossTabTask
> 'Task_T','month(Due_Date_DT)','MonthsInitials','Co nvert(char93),Due_Date)DT
> =
> '2003') --works on SQL server
>
> @table AS sysname, --Table to crosstab
> @onrows AS nvarchar(128), --Grouping key values(on rows)
> @onrowsalias AS sysname = NULL, --Alias for grouping column
> @oncols AS nvarchar(128), --Destination columns (on columns)
> @Date AS nvarchar(128),
> @sumcol AS sysname = NULL --Data cells
>
> Thanks,
> Sangeetha
> "Cor Ligthert [MVP]" wrote:
>
>> Gurvar,
>>
>> Have a look at this sample on our website. That you use a Stored
>> Procedure
>> is completely inrelevant for programming with AdoNet. It only tells
>> that
>> you
>> have the command on the server.
>>
>> http://www.vb-tips.com/default.aspx?...6-7139b8970071
>>
>> I hope this helps,
>>
>> Cor
>>
>>
>>


Apr 2 '06 #7

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

Similar topics

3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx...
5
by: Enyi | last post by:
Just like my last post I cannot solve this problem with a stored procedure in MSSQL Server 2000 Developer Edition. I am trying to use the parameter in VB.NET 2003. When I run the VB code and...
9
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio...
1
by: Routergal | last post by:
Dear SQL gurus, I am so new at this, as a matter of fact this is my first Access Database front-end with a SQL back-end. I wrote a stored procedure to show liability for vacation accrued: ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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
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
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
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.