Showing posts with label updatecommand. Show all posts
Showing posts with label updatecommand. Show all posts

Wednesday, March 7, 2012

DeleteCommand, Stored Procedures, and ReturnValue Parameters = cant be done?

I've a SqlDataSource control that has stored procedures specified for each of its commands: SelectCommand, InsertCommand, UpdateCommand, DeleteCommand . And for Insert, Update and Delete, I've specified asp:parameters for each stored procedure's parameters. Now, my stored procedures all have return values, and I've successfully accessed the return values for Insert and Update, but for some reason, I'm getting very wrong results for Delete.
<DeleteParameters>
<asp:Parameter Name="result" Type="Int32" Direction="ReturnValue" />
<asp:Parameter Name="myID" Type="Int32" />
</DeleteParameters>

The moment I add my "result" with the direction ReturnValue, I instantly get a"Procedure or function <storedprocedurename> has too many arguments specified." error. I checked my SQL Profiler, and it seems that the page is passing result as an Input parameter, instead of keeping it as a ReturnValue! e.g.

exec spName @.myID=1,@.result=NULL

when it should be

exec spName @.myID=1

I get the correct behavior with Update and Insert, so I'm wondering whether if this is a bug or by-design behavior or something very screwy with my computer?

Help? Thoughts?

Hi there,

I hope you are using the "out" keyword for the parameter that needs to be passed out.

Why dont you specify the default value for the out parameter in the asp:Parameter list?

thanks,

Murthy here

|||

Do you mean the OUTPUT keyword for the stored procedures? I'm not using OUTPUT parameters, I'm looking for the ReturnValue. What I'm actually doing is trying to access the ReturnValue of the stored procedure, like below

create procedure spTest
@.myID int = 0As
'some sql statements herereturn 1GO

The value I am interested in is1.The problem, however, is that my parameter, even though it's specified as a ReturnValue, it seems to act as an Input value regardless. And it end up passing the parameter into the stored procedure when it's not supposed to at all.

However, if I'm misunderstanding your solution: where exactly should I be using this keyword?

|||

Ok are you running the stored procedure manually?

If yes, you can check the number of rows affected as:

int status=command1.ExecuteNonQuery().

and then if the status is -1 then no rows have been affected else count is greater than 0.

You do not have to explicitly add a return value to check the status of the stored procedure. Hope I am clear.\

thanks,

Murthy here

|||

No, I'm not running the stored procedure manually. Yes, I know I am able to get the status (although your example returns rows affected, right?) if I were. [The reason why I'm checking the returnvalue is because there are various reasons why the process may fail, and in each instance, I return a different value to depict it.]

My question/problem is that setting theReturnValue parameters for theSQLDataSource control'sDELETE command does NOT seem to work (although I feel it should); instead it seems to ignore the direction and sets it to Input. I'm half-convinced this is a bug-- so I've moved on to using ObjectDataSource instead.

|||

Whatever works for you,

Murthy here

|||

Hi Jnghh,

You may visit the link http://forums.asp.net/thread/1670367.aspx which has the solution to these similar problems.

Hope it helps.

Thanks.

DeleteCommand and UpdateCommand

I have added a gridview and under its properties i have changed AutoGenerateDeleteButton and AutoGenerateEditButton to true.

The problem is... when I try and delete a record, I get this error: Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified

If I try and update.. i get the error: Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.

Can someone please help me out... maybe with some code... or a link to a tutorial..

Thanks

Canning

When you configure your datasource, you need to choose "Advanced". On the Advanced page, you need to check "Generate Insert,Update and Delete commands". This will generate attributes in your sqldatasource that allow for these things to happen. Make sure you have a primary key in your table set.|||

Hi,

I have the same problem. I tried to change the advanced setting as you specified. However, it is not allowing me to do so. The check boxes are greyed out.

Any suggestions?

thanks..

|||Greyed out usually means there is no primary key on the table that the control can recognize.|||

Also,

I do see where it says on the advanced section that "You must have all primary key fields selected for this option to be enabled." Im not sure what that means though. I have every column in the table selected to display. That does not help though. Can you tell me where I find the primary key fields so that I can "Select" them?

thanks...

|||

I do see where it says on the advanced section that "You must have all primary key fields selected for this option to be enabled." Im not sure what that means though. I have every column in the table selected to display. That does not help though. Can you tell me where I find the primary key fields so that I can "Select" them?

thanks...

|||

I was able to figure this out...thanks...and sorry for posting that twice.

Thanks for the direction.

|||

Hi,

I have the same problem that DavidatWork. Can you send me the direction too?

|||I have the same problem however in my table I specify a primary key. I still have the options disabled. Any help?|||

WEN I tried to change the advanced setting OPTION However, it is not allowing TO DO THAT The check boxes ARE UNCHECKED IE GREYED OUT SO HOW CAN I DO UPDATE AND DELETE IN MY TABLE.hOW TO ADD PRIMARY KEY ON THE TABLE

|||

hoW TO ADD PRIMARY KEY IN TABLE QUERY I HAVENT FOUND ANY OPTION REGD PRIMARY KEY CAN U SUGGEST ME

tHANK U

bHANUPRIYA

|||

do this:

ALTER TABLE Customer ADD PRIMARY KEY (SID);

(it's not the same as having an identity column).

|||

i have the same problem can anyone tell me how to resolve it?