Gridview - how to use stored procedures to update

R

Roberto Kohler

I am trying to use a stored procedure to update a row in a Gridview but I
get the error
"Procedure or function sc_updDEPT has too many arguments specified"

The Stored procedure takes 3 parameters "sc_updDEPT @idplant, @iddept,
@deptname"

I configured the SqlDataSource to use the sc_updDEPT StoredProcedure for
updates:

UpdateCommand="sc_updDEPT"
UpdateCommandType="StoredProcedure"
ConflictDetection="CompareAllValues"

<UpdateParameters>
<asp:parameter Name="idplant" Type="Int32" />
<asp:parameter Name="iddept" Type="String" />
<asp:parameter Name="deptname" Type="String" />
</UpdateParameters>

The Primary Key in the table is "idplant, iddept"
In the Gridview I set
DataKeyNames="idplant, iddept"

When I try to do the update I get the error
Exception Details: System.Data.SqlClient.SqlException:
Procedure or function sc_updDEPT has too many arguments specified.

Any help would be appreciated
 
L

LehrSJ

I had that problem. I had some template fields where I was using a label on
the edit template to display data. I had checked "two-way" databinding.
This caused the template field to be sent to the procedure. i just needed to
uncheck the two-way databinding.
 
D

dotnw

Roberto, I am having exactly the same problem as you.

Have you solved this yet?

Thanks, regards from dnw.
 
R

Roberto Kohler

I got it to work by naming the parámeters in the stored procedures,
just like the table's column names they refer to with an "@" prepended.

They used to be:
procedure sc_updDEPTOS (
@idplanta INT,
@iddepto VARCHAR(16),
@nomdepto VARCHAR(40)
)
and it didn't work.

It worked when I changed it to

procedure sc_updDEPTOS (
@dp_idplanta INT,
@dp_iddepto VARCHAR(16),
@dp_nomdepto VARCHAR(40)
)

The updateParameters in the SQLDataSource are defined as:

<UpdateParameters>
<asp:parameter Name="dp_idplanta" Type="Int32" />
<asp:parameter Name="dp_iddepto" Type="String" />
<asp:parameter Name="dp_nomdepto" Type="String" />
</UpdateParameters>
 
M

Meeran Mohideen

Hi Roberto,
I had try this solutions but it not working.its showing
same error.Give me some solutions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top