BizTalk Blog by Chris Han

BizTalk, ASP.NET, C#, SQL server, Visual studio

  Home  |   Contact  |   Syndication    |   Login
  59 Posts | 7 Stories | 80 Comments | 82 Trackbacks

News

Article Categories

Archives

Post Categories

Image Galleries

BizTalk Bloggers

BizTalk on MSDN

Patterns & Architecture

SharePoint

This is about VisualStudio beta 2 June.
I was trying to create a template step for my registeruserwizard with a Formview control. It causes me a whole weekend to figure this out .
Here is the Sp:

CREATE PROCEDURE sp_insertEp
       
 @FirstName nvarchar(10),
        @LastName nvarchar(20) ,
        @Title nvarchar(30),
        @Notes nvarchar(200),
 @CreatedBy uniqueidentifier =NULL,
        @PK_New uniqueidentifier =NULL OUTPUT
      AS
begin

 SET @PK_New = newid()
        INSERT INTO Ep(FirstName,LastName,Title,Notes,CreatedBy,EmployeeID)VALUES (@FirstName,@LastName,@Title,@Notes,@CreatedBy,@PK_New)
        RETURN (1)

end
GO

And here is the page that generated the 'Procedure or function has too many arguments specified' error:

<%@Page Language="C#" %>

<%@Import Namespace="System.Data" %>

<%@Import Namespace="System.Data.Common" %>

<%@Import Namespace="System.Data.SqlClient" %>

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">

protected void On_Inserting(object sender, SqlDataSourceCommandEventArgs e)

{

SqlParameter createdBy = new SqlParameter("@CreatedBy", SqlDbType.UniqueIdentifier);

createdBy.Direction = ParameterDirection.Input;

createdBy.Value = new Guid("8CD648F7-ECF1-4A3A-BBCD-C464D427C5EB");

e.Command.Parameters.Add(createdBy);

SqlParameter insertedKey = new SqlParameter("@PK_New", SqlDbType.UniqueIdentifier);

insertedKey.Direction = ParameterDirection.InputOutput;

e.Command.Parameters.Add(insertedKey);

 

SqlParameter retVal = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);

retVal.Direction = ParameterDirection.ReturnValue;

e.Command.Parameters.Add(retVal);

}

protected void On_Inserted(object sender, SqlDataSourceStatusEventArgs e)

{

DbCommand command = e.Command;

// The label displays the primary key of the recently inserted row.

Label1.Text = command.Parameters["@PK_New"].Value.ToString();

}

script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Pagetitle>

head>

<body>

<form id="form1" runat="server">

<div>

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyNorthwind %>"

InsertCommand="sp_insertEp" InsertCommandType="StoredProcedure" SelectCommand="SELECT EmployeeID, LastName, FirstName, Title, Notes, CreatedBy FROM Ep" OnInserted="On_Inserted" OnInserting="On_Inserting">

<InsertParameters>

<asp:Parameter Name="FirstName" Type="String" />

<asp:Parameter Name="LastName" Type="String" />

<asp:Parameter Name="Title" Type="String" />

<asp:Parameter Name="Notes" Type="String" />

<asp:Parameter Name="CreatedBy" >

<asp:Parameter Name="PK_New" Direction="InputOutput" />

InsertParameters>

asp:SqlDataSource>

div>

<asp:FormView ID="FormView1" runat="server" DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1"

DefaultMode="Insert">

<InsertItemTemplate>

LastName:

<asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>'>

asp:TextBox><br />

FirstName:

<asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>'>

asp:TextBox><br />

Title:

<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>'>

asp:TextBox><br />

Notes:

<asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>'>

asp:TextBox><br />

<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"

Text="Insert">

asp:LinkButton>

<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"

Text="Cancel">

asp:LinkButton>

InsertItemTemplate>

asp:FormView>

<asp:Label ID="Label1" runat="server">asp:Label>

form>

body>

html>

Notice the two lines in the gray box generated by SqlDataSource control? I also have two in my On_Inserting event handler to “Add“ these two parameters. I should either remove this two lines or change the “Add“ parameters in On_Inserting event handler to simply assign value like this:

 

SqlParameter insertedKey = e.Command.Parameters["@PK_New"];  //new SqlParameter("@PK_New", SqlDbType.UniqueIdentifier);

insertedKey.Direction = ParameterDirection.InputOutput;

//e.Command.Parameters.Add(insertedKey);

insertedKey.SqlDbType = SqlDbType.UniqueIdentifier;

That's the bad boy. Apparently, SqlDataSource control doesn't like “uniqueidentifier” type. You can work around this by just removing that two lines from <InsertParameters> tag, and handlling them in the ON_Inserting event by yourself. 

posted on Saturday, July 02, 2005 12:21 PM

Feedback

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 7/14/2005 2:33 AM Henri Löbel
Hello,

I have the same problems, but your solution does not work at my website:

The Datasource of DetailsView1:
InsertCommand="uspTestInsert" InsertCommandType="StoredProcedure" SelectCommand="SELECT TestOid, TestId, Name, ShortName, Description, Remark, ValidFrom, ValidTo, CreatedAt, CreatedBy, CreatedByIp, ChangedAt, ChangedBy, ChangedByIp FROM tblTest" OnInserted="SqlDataSource1_Inserted" OnInserting="SqlDataSource1_Inserting">
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ShortName" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Remark" Type="String" />
<asp:Parameter Name="ValidFrom" Type="DateTime" />
<asp:Parameter Name="ValidTo" Type="DateTime" />
<asp:Parameter Name="CreatedAt" Type="DateTime" />
<asp:Parameter Name="CreatedBy" Type="String" />
<asp:Parameter Name="CreatedByIp" Type="String" />
</InsertParameters>


The event in Codefile:

protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
SqlParameter organizationOid = new SqlParameter("@OrganizationOid", SqlDbType.UniqueIdentifier);
organizationOid.Direction = ParameterDirection.Input;
organizationOid.Value = Guid.NewGuid();
e.Command.Parameters.Add(organizationOid);
SqlParameter organizationId = new SqlParameter("@OrganizationId", SqlDbType.UniqueIdentifier);
organizationId.Direction = ParameterDirection.Input;
organizationId.Value = Guid.NewGuid();
e.Command.Parameters.Add(organizationId);
}

Is it possible, that this problem is caused by different count of fields? The select-statement has more rows then the insert.


# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 7/14/2005 12:34 PM ChrisHan
I'll have to start a new thread to reply this.
.Text can't handle long comments?

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 7/14/2005 12:35 PM ChrisHan
One thing I notice in your SqlDataSource1_Inserting handler is you have parameters "@OrganizationOid" and "@OrganizationId" which are not your your select command. Try to make them same name and see if it helps. Also could you post your usp and table DDL here if it does work? That'll help me to reproduce your issues.

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 7/14/2005 12:36 PM ChrisHan
Well, actually "The select-statement has more rows then the insert" is a right thing to do. Other wise, you may get "could not find a non-generic method " error. Please see my other blog on this.

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 11/16/2005 1:21 PM Scott Mitchell
Doesn't look like they've fixed this problem in RTM. :-(

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 11/18/2005 7:12 AM Soulhuntre
Total abject failure in RTM.

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 11/18/2005 7:34 AM Soulhuntre
I found a semi work around.

See the link for more info.

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 1/2/2006 3:31 PM fabio
I was receiving this same error, but it was due to another issue all together. I had a formview control with 8 bound labels using the bind method . . . <#% bind("myfield") %> . . . on the item template. But, my update method only took in 2 parameters. Because the bind method was being used, trying to update a record would send the 2 parameters specified for the update AND the 8 specified for the select into my stored proc. . . which naturally gave said error. The solution was to use the read only method "eval" instead of bind . . . <#% eval("myfield") %> in the fields that I was not updating.

# 'Procedure or function has too many arguments specified' error 5/9/2006 6:36 AM Shah Nawaz
good
but i am still facing a problem due to this error in ASP.Net

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 5/26/2006 12:24 PM Asad
just solved my problem. its was just a small thing. here is what u need to do. select sqlcommand. u must have made a connection and a sqlcommand inorder to execute a query. in the properties of sqlcommand there is a field called collection. click this. here you'll see that 2 arguements have been set already. now when u add new paramters by sqlcommand.parameters.add (blah,blah) u get the error msg. u must remove the extra arguments specified in collection field of sqlcommand. i hope this solves your problem

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 7/13/2006 7:45 PM DaleS
I'd had a similar problem. I found another link that mentioned there is a bug when dealing with uniqueidentifier. It mentioned that it put's a type=text on the control in the ASP. Remove the type. It did the trick for me.

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 8/9/2006 11:12 PM Dougnutz
I have had this problem several times when dealing with Guids, but it's not limited to them. Onething that has worked for me is to do something like this in the controls on deleting event (a gridview in this case)

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlDataSourceQuotes.DeleteParameters.Clear();
SqlDataSourceQuotes.DeleteParameters.Add("my_ID", e.Keys["my_ID"].ToString());
SqlDataSource1.Delete();
e.Cancel = true;
GridView1.DataBind();

}

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 9/6/2006 6:45 AM PM
I had similar problem, within a sql connection transaction workarea, I passed same sqlcmd. The same sqlcmd was used for differnt storedprocedures with different parameters. Problem solved after clearing parameters
sqlCmd.Parameters.Clear();
before sqlcmd loads new stored procedures each time.

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 11/1/2006 6:01 PM Ben
I had a similar problem with FormView passing too many parameters to a proc. This was my solution:

http://mcsdeveloper.wordpress.com/2006/11/01/formview-control-sqldatasource-and-procedure-or-function-has-too-many-arguments-specified-error/

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 6/13/2007 8:03 AM KIM
yes the solution to delete the parameters first then add your parameters :

protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
if (_Old_FullName == _New_FullName)
{
e.Cancel = true;
}
else
{
e.Command.Parameters.Clear();
System.Data.SqlClient.SqlParameter param1 = new System.Data.SqlClient.SqlParameter(&quot;@UserName&quot;, _UserName);
System.Data.SqlClient.SqlParameter param2 = new System.Data.SqlClient.SqlParameter(&quot;@FullName&quot;, _New_FullName);
e.Command.Parameters.Add(param1);
e.Command.Parameters.Add(param2);
}
}

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 8/9/2007 12:26 PM Jportelas
sometimes it´s good to do a parameters.clear() call before adding new parameters to a stored procedure call, cause if you use the same connection, parameters are kept from call to call.

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 11/21/2007 5:47 AM Gintas
Thanks, Buddy. Much appreciated. Exactly what
I've been looking for.

# re: EASY SOLUTION 1/23/2008 8:33 PM Allen
I spent half a day today fighting this error and trying to figure out what the hell is going on.

Basically, the names in your InsertParameters or whatever parameters you are using, have to match EXACTLY the parameter names in the stored procedure. One misspelling, and ADO adds another parameter to your list. That's all it is.
CHECK YOUR SPELLING!!!!

# re: FormView control, SqlDataSource, and 'Procedure or function has too many arguments specified' error 3/24/2008 11:28 AM Marco Fresegna
For me the problem was this:

in my stored procedure for updating the record, I had the parameter:

@UserId uniqueidentifier

But Visual Studio, creating the FormView, generated this:

<asp:Parameter Name="UserId" Type="Object" />

causing the 'Procedure or function has too many arguments specified' error at run-time.

My solution was to change the Type of the parameter from "Object" to "String":

<asp:Parameter Name="UserId" Type="Object" />

This solved all problems!

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 2 and 5 and type the answer here: