AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Update rows in multitable using store procedure in gridview
Posted by Manisha on  3/16/2010 4:53:50 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
I m using asp.net 2.0 and sql server.

I want to update records of gridview using store procedure.

This is my store procedure :

ALTER PROCEDURE welspun.usp_AddROle
@EmpId varchar(8),
@Role varchar(8)

AS

declare @RoleId int
set @RoleId=(select RoleId from TC_ROLE where Role=@Role)

update TM_EMP set RoleId=@RoleId where EmpId=@EmpId
RETURN


Code for it:

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:con %>"

SelectCommand="SELECT dbo.TM_EMP.EmpId, dbo.TC_ROLE.Role, dbo.TC_ROLE.InsertDate, dbo.TC_ROLE.InsertBy
FROM dbo.TM_EMP CROSS JOIN dbo.TC_ROLE
WHERE (dbo.TM_EMP.RoleId = dbo.TC_ROLE.RoleId)"

UpdateCommand="usp_AddRole" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="EmpId" Type="String" />
<asp:Parameter Name="Role" Type="String" />
</UpdateParameters>

</asp:SqlDataSource>


<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" BackColor="#CCCCCC"
BorderColor="#999999"
BorderStyle="Solid"
BorderWidth="3px"
CellPadding="4"
CellSpacing="2"
DataKeyNames="EmpId,Role"
DataSourceID="SqlDataSource2"
ForeColor="Black">
<FooterStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowEditButton="True" />

<asp:BoundField DataField="EmpId"
HeaderText="EmpId"
ReadOnly="True"
SortExpression="EmpId" />

<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />

<asp:BoundField DataField="InsertDate" HeaderText="InsertDate" SortExpression="InsertDate" />

<asp:BoundField DataField="InsertBy" HeaderText="InsertBy" SortExpression="InsertBy" /> </Columns>
<RowStyle BackColor="White" />

<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />

<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />


<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />

</asp:GridView>

It gives error "System.Data.SqlClient.SqlException: Procedure or function usp_AddRole has too many arguments specified."

So pls help me to find out solution..


Post Your Reply Post New Question

 Viewer's Reply
Update Rows with Stored Procedure and SqlDataSource
Answered By Moderator1 on 3/20/2010 11:25:58 PM
Hi,

I've checked the code, could not able to find any problem in it.. Please reply back if you find the solution. Thanks.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Backup and Recovery Best Practices for Microsoft SQL Server 2005
Web Application Security — How to Minimize Prevalent Risk of Attacks
Simply SQL - Free 111 Page Preview!