Solved

Error with insert using stored procedure with GridView and SqlDataSource controls

Posted on 2006-12-01
2
756 Views
Last Modified: 2011-10-03
Hello!

I'm having problems adding a record using a stored procedure with the GridView and SQlDataSource controls. When I click the "Add" button, I get the following error:

Procedure or Function 'spAddCompetitor' expects parameter '@name', which was not supplied.

I have provided the source code below.

Any thanks is much appreciated.

Simon

------------
ASPX FILE:
-------------

        <div id="Content">
            <h1>Players</h1>
            <asp:GridView ID="grdPlayers" runat="server" AutoGenerateColumns="False" DataSourceID="TournamentPlayers" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataKeyNames="CompetitorID" >            
            <Columns>                
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField Visible="False" DataField="CompetitorID" />
            </Columns>
           
            </asp:GridView>
            <h2>Add Player</h2>
            <asp:SqlDataSource ID="TournamentPlayers" runat="server" ConnectionString="<%$ ConnectionStrings:TournamentsConnectionString %>"
                SelectCommand="SELECT [CompetitorID], [Name] FROM [Competitor]"
                InsertCommand="spAddCompetitor"                
                InsertCommandType="StoredProcedure">
                <InsertParameters>                    
                    <asp:FormParameter FormField="txtPlayerName" Name="@name" Type="string" Size="50" />                  
                </InsertParameters>
            </asp:SqlDataSource>
            <table>
                <tr>
                    <td>Name:</td>
                    <td><asp:TextBox runat="server" ID="txtPlayerName"/></td>
                    <td><asp:Button runat="server" ID="btnAddPlayer" Text="Add" OnClick="btnAddPlayer_Click"/></td>
                </tr>
            </table>
        </div>  

-------------------------
STORED PROCEDURE:
-------------------------

ALTER PROCEDURE dbo.spAddCompetitor       
      @name varchar(50)
AS
      SET NOCOUNT ON
      
      insert into Competitor([Name])
      values (@name)
      
      RETURN

---------------------------------
"ADD" BUTTON CLICK CODE:
---------------------------------

protected void btnAddPlayer_Click(object sender, EventArgs e)
    {        
        TournamentPlayers.Insert();        
    }
0
Comment
Question by:dhtml
2 Comments
 
LVL 6

Accepted Solution

by:
manicsquirrel earned 500 total points
Comment Utility
My first thought would be to change this line:
<asp:FormParameter FormField="txtPlayerName" Name="@name" Type="string" Size="50" />

to

<asp:FormParameter FormField="txtPlayerName" Name="name" Type="string" Size="50" />

No "@".  The SQL datasource would add this to the param before it passes it.
0
 

Author Comment

by:dhtml
Comment Utility
Thanks for that - I knew it would be something simple.

Unfortunately, I've got another problem now (grid doesn't show the new row unless I re-visit the page), but that's a separate issue so I'll post that question if I can't find the answer myself.

Simon
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now