Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 9th, 2009, 09:47 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , .
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default Pass parameters to stored procedure from GridView

Hi,

I have a GridVeiw control on my WEB page which is populated from the "standard" SQL 2005 membership database. This control has the DELETE column to delete selected user. I am using "dbo.aspnet_Users_DeleteUser" stored procedure to do this action. This procedure has the "signature":
Code:
ALTERPROCEDURE [dbo].[aspnet_Users_DeleteUser]
@ApplicationName nvarchar(256),
@UserName nvarchar(256),
@TablesToDeleteFrom int,
@NumTablesDeletedFrom intOUTPUT
.........
........

and returns an Integer value.

When I try to delete a row from the grid, I am getting error:

Procedure or function aspnet_Users_DeleteUser has too many arguments specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Procedure or function aspnet_Users_DeleteUser has too many arguments specified.
My question is: how to specify and pass parameters to the stored procedure in my case?

Thanks in advance

-Dmitriy
  #2 (permalink)  
Old February 9th, 2009, 10:35 AM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Please post more code...

Can you post the code you are using in your codebehind and aspx page?
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #3 (permalink)  
Old February 9th, 2009, 10:49 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , .
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default Pass parameters to stored procedure from GridView

This is my Code behind:

Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
namespace LibraryFileUpload.Restricted
{
publicpartialclassUsersList : System.Web.UI.Page
{
privatestring sErrorMessage = null;
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid usersGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
Session["SelectedUserName"] = usersGridView.Rows[e.RowIndex].Cells[1].Text;
}
catch (Exception en)
{
sErrorMessage = en.Message;
Session["Message"] = "ERROR inside the usersGridView_RowDeleting() function. " + sErrorMessage + " Contact customer support,please. ";
Response.Redirect("ErrorForm.aspx", false);
}
}
protectedvoid LoginStatus2_LoggedOut(object sender, EventArgs e)
{
Session.Clear();
Session.Abandon();
}
protectedvoid SqlDataSource_Users_Deleting(object sender, SqlDataSourceCommandEventArgs e)
{
if (Session["SelectedUserName"] != null)
{
e.Command.Parameters["@ApplicationName"].Value = "/";
e.Command.Parameters["@UserName"].Value = (String)Session["SelectedUserName"];
e.Command.Parameters["@TablesToDeleteFrom"].Value = 5;
e.Command.Parameters["@NumTablesDeletedFrom"].Value = 0;
}
}
protectedvoid usersGridView_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
sErrorMessage = e.Exception.Message;
Session["Message"] = "ERROR inside the usersGridView_RowDeleted() function. " + sErrorMessage + " Contact customer support,please. ";
Response.Redirect("ErrorForm.aspx", false);
}
}
}
}
And this is my form:

Code:
<%@PageLanguage="C#"MasterPageFile="~/Restricted/LibraryFileUpload4.Master"AutoEventWireup="true"CodeBehind="UsersList.aspx.cs"Inherits="LibraryFileUpload.Restricted.UsersList"Title="Untitled Page" %>
<asp:ContentID="Content1"ContentPlaceHolderID="head"runat="server">
<styletype="text/css">
.styleTitle
{
font-weight: bold;
text-decoration: underline;
height: 80px;
}
.style7
{
font-weight: bold;
text-decoration: underline;
height: 43px;
}
.styleWaitMessage
{
font-weight: bold;
color: Blue;
}
</style>
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="ContentPlaceHolder1"runat="server">
<%--<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>--%>
<tablestyle="width: 100%;">
<tr>
<tdalign="center">
<tablestyle="width: 100%;">
<trvalign="top">
<tdalign="center"class="style7">
<fontcolor="#336699"size="4">Users List Screen</font>
</td>
</tr>
<tr>
<tdalign="center">
<br/>
<asp:UpdateProgressID="UpdateProgress1"runat="server">
<ProgressTemplate>
<divclass="styleWaitMessage">
<imgsrc="../Images/spinner3-bluey.gif"/> Processing ... Wait, please.
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
<trclass="style6">
<tdalign="center">
<asp:GridViewID="usersGridView"runat="server"AllowPaging="True"AllowSorting="True"BorderStyle="Double"BorderWidth="2px"CellPadding="4"CellSpacing="2"EnableSortingAndPagingCallbacks="True"Font-Bold="True"ForeColor="#333333"Width="346px"AutoGenerateColumns="False"DataSourceID="SqlDataSource_Users"onrowdeleting="usersGridView_RowDeleting"DataKeyNames="UserName"onrowdeleted="usersGridView_RowDeleted">
<FooterStyleBackColor="#5D7B9D"Font-Bold="True"ForeColor="White"/>
<RowStyleBackColor="#F7F6F3"ForeColor="#333333"/>
<Columns>
<asp:CommandFieldButtonType="Button"ShowDeleteButton="True"/>
<asp:BoundFieldDataField="UserName"HeaderText="UserName"SortExpression="UserName"/>
<asp:BoundFieldDataField="Email"HeaderText="Email"SortExpression="Email"/>
<asp:BoundFieldDataField="CreateDate"HeaderText="CreateDate"SortExpression="CreateDate"/>
</Columns>
<PagerStyleBackColor="#284775"ForeColor="White"HorizontalAlign="Center"/>
<SelectedRowStyleBackColor="#E2DED6"Font-Bold="True"ForeColor="#333333"/>
<HeaderStyleBackColor="#5D7B9D"Font-Bold="True"ForeColor="White"/>
<EditRowStyleBackColor="#999999"/>
<AlternatingRowStyleBackColor="White"ForeColor="#284775"/>
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource_Users"runat="server"ConnectionString="<%$ ConnectionStrings:MyFileUploadDBConnectionString %>"SelectCommand="SELECT aspnet_Users.UserName, aspnet_Membership.Email, aspnet_Membership.CreateDate FROM aspnet_Users INNER JOIN aspnet_Membership ON aspnet_Users.UserId = aspnet_Membership.UserId"DeleteCommandType="StoredProcedure"DeleteCommand="dbo.aspnet_Users_DeleteUser"ondeleting="SqlDataSource_Users_Deleting">
<DeleteParameters><asp:ParameterDirection="ReturnValue"Name="RETURN_VALUE"Type="Int32"DefaultValue=""/>
<asp:ParameterName="ApplicationName"Type="String"DefaultValue=""/>
<asp:ParameterDefaultValue=""Name="UserName"Type="String"></asp:Parameter>
<asp:ParameterDefaultValue=""Name="TablesToDeleteFrom"Type="Int32"/>
<asp:ParameterDefaultValue=""Direction="InputOutput"Name="NumTablesDeletedFrom"Type="Int32"/>
</DeleteParameters>
</asp:SqlDataSource>
</td>
</tr>
</table></td>
<tdalign="right"valign="top"width="50px">
<asp:LoginStatusID="LoginStatus2"runat="server"Height="31px"ToolTip="User Login/Logout"Width="46px"onloggedout="LoginStatus2_LoggedOut"/>
</td>
</tr>
</table>
<%--</ContentTemplate>
</asp:UpdatePanel> --%> 
</asp:Content>
Should I specify the returned value as well?
  #4 (permalink)  
Old February 9th, 2009, 11:01 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there..

I can see why you have the error. I don't understand why you are doing such a mess with a direct delete (or there is something I'm missing?)

Code:
<DeleteParameters><asp:ParameterDirection="ReturnValue"Name="RETURN_VALUE"Type="Int32"DefaultValue=""/>
<asp:ParameterName="ApplicationName"Type="String"DefaultValue=""/>
<asp:ParameterDefaultValue=""Name="UserName"Type="String"></asp:Parameter>
<asp:ParameterDefaultValue=""Name="TablesToDeleteFrom"Type="Int32"/>
<asp:ParameterDefaultValue=""Direction="InputOutput"Name="NumTablesDeletedFrom"Type="Int32"/>
</DeleteParameters>
Or I'm missing something (and if that happens I'm terrible sorry) or you are passing 5 parameters to the SP?
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
  #5 (permalink)  
Old February 9th, 2009, 11:04 AM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Noticed that too...

I was just about to post the same thing...

Looks like you are duplicating your output... remove this line right here and then try
<asp:ParameterDirection="ReturnValue"Name="RETURN_ VALUE"Type="Int32"DefaultValue=""/>
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #6 (permalink)  
Old February 9th, 2009, 11:17 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , .
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default My mistake...

Gentlemen,
Thank you very much. I do not know how I included this returned parameter on the form? Thanks for your input again!

-Dmitriy
  #7 (permalink)  
Old February 9th, 2009, 11:19 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

I am just really curious as to why one wouldn't just use the methods from the Membership classes to do this.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #8 (permalink)  
Old February 9th, 2009, 11:27 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , .
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Yes,
I've tryed to use code like this:

Code:
protectedvoid usersGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
Membership.DeleteUser(usersGridView.Rows[e.RowIndex].Cells[1].Text);
Response.Redirect("Administration.aspx", false);
}
catch (Exception en)
{
sErrorMessage = en.Message;
Session["Message"] = "ERROR inside the usersGridView_RowDeleting() function. " + sErrorMessage + " Contact customer support,please. ";
Response.Redirect("ErrorForm.aspx", false);
}
}


But it is giving me an error and does not update the grid?
  #9 (permalink)  
Old February 9th, 2009, 11:50 AM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Well...

what's the error it's giving you?
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #10 (permalink)  
Old February 9th, 2009, 11:59 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Yes, what is the error?

And, by the way, GridViews don't update themselves. You have to rebind them when the underlying data changes.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass value to stored procedure? hertendreef SQL Server 2005 3 February 23rd, 2007 11:43 AM
How to pass a parameter to a stored procedure? MaxGay2 VB.NET 2002/2003 Basics 1 November 8th, 2006 02:48 PM
stored procedure with parameters Danmalam VB Databases Basics 0 February 27th, 2005 03:52 PM
How will I pass stored procedure in an asp shoakat SQL Server 2000 1 July 15th, 2004 11:28 PM
SQL Pass though parameters to stored procedures blinton25 SQL Server 2000 3 March 29th, 2004 02:49 PM



All times are GMT -4. The time now is 05:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.