Solved

Error with insert using stored procedure with GridView and SqlDataSource controls

Posted on 2006-12-01
2
762 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 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