473,566 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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. Conflictdetecti on set to compareallvalue s.
Oldvaluesparame terformatstring set to original_{0}
tblA has 2 fields. ID and MyText.

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

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_MyTex t as nvarchar (255)
)

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

/jim
Mar 2 '06 #1
3 6390

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

SqlConnection conn = new SqlConnection(m yConnectionStri ng);
SqlCommand execProc = new SqlCommand("Del Proc", conn);
execProc.Comman dType = CommandType.Sto redProcedure;

execProc.Parame ters.Add("@orig inal_ID ", SqlDbType.NVarC har, 255).Value =
YourValue;
execProc.Execut eScalar();

Hope that helps,
Alex.
"Jim Andersen" <no****@nospam. dk> wrote in message
news:e5******** ******@TK2MSFTN GP11.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. Conflictdetecti on set to compareallvalue s.
Oldvaluesparame terformatstring set to original_{0}
tblA has 2 fields. ID and MyText.

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

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_MyTex t as nvarchar (255)
)

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

/jim

Mar 2 '06 #2

"Alex D." <al********@hot mail.com> skrev i en meddelelse
news:Oz******** *****@TK2MSFTNG P15.phx.gbl...

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

SqlConnection conn = new SqlConnection(m yConnectionStri ng);
SqlCommand execProc = new SqlCommand("Del Proc", conn);
execProc.Comman dType = CommandType.Sto redProcedure;

execProc.Parame ters.Add("@orig inal_ID ", SqlDbType.NVarC har, 255).Value =
YourValue;
execProc.Execut eScalar();
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.Tex t instead of Commandtype.Sto redprocedure.

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

And my stored proc don't have, or need, a @original_sortn o 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******** ******@TK2MSFTN GP11.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. Conflictdetecti on set to compareallvalue s.
Oldvaluesparame terformatstring set to original_{0}
tblA has 2 fields. ID and MyText.

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

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_MyTex t as nvarchar (255)
)

even though I don't use @original_MyTex t 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.Sto redProcedure. 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******** *****@TK2MSFTNG P14.phx.gbl...

"Alex D." <al********@hot mail.com> skrev i en meddelelse
news:Oz******** *****@TK2MSFTNG P15.phx.gbl...

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

SqlConnection conn = new SqlConnection(m yConnectionStri ng);
SqlCommand execProc = new SqlCommand("Del Proc", conn);
execProc.Comman dType = CommandType.Sto redProcedure;

execProc.Parame ters.Add("@orig inal_ID ", SqlDbType.NVarC har, 255).Value =
YourValue;
execProc.Execut eScalar();


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.Tex t instead of Commandtype.Sto redprocedure.

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

And my stored proc don't have, or need, a @original_sortn o 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******** ******@TK2MSFTN GP11.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. Conflictdetecti on set to compareallvalue s.
Oldvaluesparame terformatstring set to original_{0}
tblA has 2 fields. ID and MyText.

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

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_MyTex t as nvarchar (255)
)

even though I don't use @original_MyTex t 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
1581
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 out of the query, it works. What seems to be happening is that if a field is NULL when it is read in through the select statement, it's causing the...
3
11274
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: <asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings: ConnectionString1 %>" SelectCommand="UserLkp"...
3
8944
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> <asp:Parameter Name="MerchID" Type="Int32" /> <asp:Parameter Name="Merchant" Type="String" /> <asp:Parameter Name="ModifiedBy" Type="String" />...
0
1601
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 control (Stored Procedure with 2 input parameters). The GridView contains 3 columns (QuestionNumber, QuestionText, and a TemplateField). The...
2
9884
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 longer but this should illustrate the problem: <asp:FormView ID="bookFormView" runat="server" DataSourceID="bookSqlDataSource"> <ItemTemplate>...
9
2207
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. How do I get this working? -- Thank you kindly, Dan Sikorsky BA, BSCE, MCS
1
12296
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 poor soul. Situation: I want to do a lookup using a stored procedure for each value in a Row within a GridView. I use a lookup function in my...
1
6117
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 label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the...
0
1160
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" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString%>" ProviderName="<%$ ConnectionStrings:MyConnectionString.ProviderName...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
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...
0
7951
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 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...
0
6260
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
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
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.