Solved

Error with insert using stored procedure with GridView and SqlDataSource controls

Posted on 2006-12-01
2
767 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
manicsquirrel earned 500 total points
ID: 18054497
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
ID: 18054922
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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