473,403 Members | 2,293 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,403 software developers and data experts.

SqlDataSource, SQL working, Stored procedure doesn't. Parameter hell

Just to let you know, and to help any future sorry sods who gets trapped in
the same black hole......

You can't just copy/move a working sql-statement into a stored procedure.

Working with a sqldatasource. Conflictdetection set to compareallvalues.
Oldvaluesparameterformatstring set to original_{0}
tblA has 2 fields. ID and MyText.

Deletecommand="Delete from tblA where ID=@original_ID"
No deleteparameters.

Works great.

Ok, so I've finished testing, and wanna move from embedded sql to using
stored procs instead.
So I change
Deletecommand="DelProc"
and
create DelProc (
@original_ID as nvarchar (255)
)
as
Delete from tblA where ID=@original_ID

BUT... I get errors stating there are too many arguments (or parameters) to
DelProc. I have to change DelProc to
create DelProc (
@original_ID as nvarchar (255),
@original_MyText as nvarchar (255)
)

even though I don't use @original_MyText but have the same Delete statement
as before.

/jim
Mar 2 '06 #1
3 6378

How are you calling the stored procedure? you need something like below:

SqlConnection conn = new SqlConnection(myConnectionString);
SqlCommand execProc = new SqlCommand("DelProc", conn);
execProc.CommandType = CommandType.StoredProcedure;

execProc.Parameters.Add("@original_ID ", SqlDbType.NVarChar, 255).Value =
YourValue;
execProc.ExecuteScalar();

Hope that helps,
Alex.
"Jim Andersen" <no****@nospam.dk> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
Just to let you know, and to help any future sorry sods who gets trapped
in the same black hole......

You can't just copy/move a working sql-statement into a stored procedure.

Working with a sqldatasource. Conflictdetection set to compareallvalues.
Oldvaluesparameterformatstring set to original_{0}
tblA has 2 fields. ID and MyText.

Deletecommand="Delete from tblA where ID=@original_ID"
No deleteparameters.

Works great.

Ok, so I've finished testing, and wanna move from embedded sql to using
stored procs instead.
So I change
Deletecommand="DelProc"
and
create DelProc (
@original_ID as nvarchar (255)
)
as
Delete from tblA where ID=@original_ID

BUT... I get errors stating there are too many arguments (or parameters)
to DelProc. I have to change DelProc to
create DelProc (
@original_ID as nvarchar (255),
@original_MyText as nvarchar (255)
)

even though I don't use @original_MyText but have the same Delete
statement as before.

/jim

Mar 2 '06 #2

"Alex D." <al********@hotmail.com> skrev i en meddelelse
news:Oz*************@TK2MSFTNGP15.phx.gbl...

How are you calling the stored procedure? you need something like below:

SqlConnection conn = new SqlConnection(myConnectionString);
SqlCommand execProc = new SqlCommand("DelProc", conn);
execProc.CommandType = CommandType.StoredProcedure;

execProc.Parameters.Add("@original_ID ", SqlDbType.NVarChar, 255).Value =
YourValue;
execProc.ExecuteScalar();
But _I_ don't call the stored procedure. The SqlDataSource calls it. I just
tell it:

Deletecommand="DelProc"

I am working with a master-detail scenario using a GridView-DetailsView. And
the DetailsView is bound to SqlDataSource. I hit the Delete button in the
DetailsView, and the record gets deleted.

So I don't call my proc. The DetailsView tells the SqlDataSource to delete a
record. But SqlDataSource apparently uses parameters differently (or calls
differently, or handles errors differently) when the DeleteCommand has
Commandtype.Text instead of Commandtype.Storedprocedure.

As far as I can tell, the SqlDataSource does the same as you suggested, BUT
it also does:
execProc.Parameters.Add("@original_sortno ", SqlDbType.Int, 4).Value =
YourValue;

And my stored proc don't have, or need, a @original_sortno parameter. And
thats why I get a "U're calling DelProc with too many parameters, Dude!"
error message.

/jim

"Jim Andersen" <no****@nospam.dk> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
Just to let you know, and to help any future sorry sods who gets trapped
in the same black hole......

You can't just copy/move a working sql-statement into a stored procedure.

Working with a sqldatasource. Conflictdetection set to compareallvalues.
Oldvaluesparameterformatstring set to original_{0}
tblA has 2 fields. ID and MyText.

Deletecommand="Delete from tblA where ID=@original_ID"
No deleteparameters.

Works great.

Ok, so I've finished testing, and wanna move from embedded sql to using
stored procs instead.
So I change
Deletecommand="DelProc"
and
create DelProc (
@original_ID as nvarchar (255)
)
as
Delete from tblA where ID=@original_ID

BUT... I get errors stating there are too many arguments (or parameters)
to DelProc. I have to change DelProc to
create DelProc (
@original_ID as nvarchar (255),
@original_MyText as nvarchar (255)
)

even though I don't use @original_MyText but have the same Delete
statement as before.

/jim


Mar 3 '06 #3
I think that is your mistake, you need to do something like I stated before.
SqlCommand need to be set to CommandType.StoredProcedure. What happens is
that the way you are doing it is for TransactSQL constructions but not for
calling stored procedures.

"Jim Andersen" <no****@nospam.dk> wrote in message
news:ex*************@TK2MSFTNGP14.phx.gbl...

"Alex D." <al********@hotmail.com> skrev i en meddelelse
news:Oz*************@TK2MSFTNGP15.phx.gbl...

How are you calling the stored procedure? you need something like below:

SqlConnection conn = new SqlConnection(myConnectionString);
SqlCommand execProc = new SqlCommand("DelProc", conn);
execProc.CommandType = CommandType.StoredProcedure;

execProc.Parameters.Add("@original_ID ", SqlDbType.NVarChar, 255).Value =
YourValue;
execProc.ExecuteScalar();


But _I_ don't call the stored procedure. The SqlDataSource calls it. I
just tell it:

Deletecommand="DelProc"

I am working with a master-detail scenario using a GridView-DetailsView.
And the DetailsView is bound to SqlDataSource. I hit the Delete button in
the DetailsView, and the record gets deleted.

So I don't call my proc. The DetailsView tells the SqlDataSource to delete
a record. But SqlDataSource apparently uses parameters differently (or
calls differently, or handles errors differently) when the DeleteCommand
has Commandtype.Text instead of Commandtype.Storedprocedure.

As far as I can tell, the SqlDataSource does the same as you suggested,
BUT it also does:
execProc.Parameters.Add("@original_sortno ", SqlDbType.Int, 4).Value =
YourValue;

And my stored proc don't have, or need, a @original_sortno parameter. And
thats why I get a "U're calling DelProc with too many parameters, Dude!"
error message.

/jim

"Jim Andersen" <no****@nospam.dk> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
Just to let you know, and to help any future sorry sods who gets trapped
in the same black hole......

You can't just copy/move a working sql-statement into a stored
procedure.

Working with a sqldatasource. Conflictdetection set to compareallvalues.
Oldvaluesparameterformatstring set to original_{0}
tblA has 2 fields. ID and MyText.

Deletecommand="Delete from tblA where ID=@original_ID"
No deleteparameters.

Works great.

Ok, so I've finished testing, and wanna move from embedded sql to using
stored procs instead.
So I change
Deletecommand="DelProc"
and
create DelProc (
@original_ID as nvarchar (255)
)
as
Delete from tblA where ID=@original_ID

BUT... I get errors stating there are too many arguments (or parameters)
to DelProc. I have to change DelProc to
create DelProc (
@original_ID as nvarchar (255),
@original_MyText as nvarchar (255)
)

even though I don't use @original_MyText but have the same Delete
statement as before.

/jim



Mar 3 '06 #4

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

Similar topics

2
by: stuart.d.jones | last post by:
Hi, I'm using a detailsview control with an SqlDataSource control. My Update query isn't working, and I've narrowed it down to the optimistic concurrency parameters - i.e. when I comment them...
3
by: michelle | last post by:
I am trying to get an output value from a stored procedure using sqlDataSource in asp.net 2.0. But I only get a null value for the output. Can someone please help? The sqlDataSource: ...
3
by: jkayne | last post by:
Can someone offer some insight of why parameters outside of those contained in a SqlDataSource <UpdateParameters> section would show up in a profiler trace? I'm using: <UpdateParameters>...
0
by: Giovanni | last post by:
I was wondering if someone would be able to help me with the following: Simply put, I have built an ASP.NET 2.0 WebUserControl (UC1). UC1 contains: A GridView which is bound to an SQLDataSource...
2
by: Ned Balzer | last post by:
I'm trying to create a formview bound to a sqldatasource, and use a stored procedure to insert data from the formview into several tables. I have some simplified code below, the real code is much...
9
by: Dan Sikorsky | last post by:
When I hit the Test Query button in the SqlDataSource design, all the rows come back. But when I run the website, without any changes, in the IDE, the GridView tied to the SqlDataSoure is empty. ...
1
by: John Bailo | last post by:
This is a my solution to getting an Output parameter from a SqlDataSource. I have seen a few scant articles but none of them take it all the way to a solution. Hopefully this will help some...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
0
by: danielhamd | last post by:
I am converting a website that uses an Access Database to SQL Server. On one particular SqlDataSource I am having a lot of trouble. Here is the original: <asp:SqlDataSource ID="SqlDataSource1"...
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...
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
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
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
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.