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
Solved

Error with insert using stored procedure with GridView and SqlDataSource controls

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 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