Click here to Skip to main content
15,881,738 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i run my application this message shows up"Procedure or function 'AddElection' expects parameter '@Election_Start', which was not supplied."

Here is my code

C#
 <head>
  <meta charset="utf-8" />
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
      $(function () {
          $("#datepicker").datepicker();
          $("#datepicker1").datepicker();
          $("#datepicker2").datepicker();
          $("#datepicker3").datepicker();
      });
  </script>
</head>

    
       <table title="Election." cellspacing="0" cellpadding="6" border="0" id="Table1" style="background-color: White; height: 100%; width: 100%; font-family: Verdana; font-size: 0.8em; border-collapse: collapse;">
        <tr>
            <td align="center" style="color: White; background-color: #284775; font-weight: bold; height: 2em;">ELECTION</td>
        </tr>
      
       <tr>
           <td>
               <table border="0" cellpadding="2" style="width: 500px;">

                   <tr>
                       <td style="color: #5D7B9D;" align="center">Election Name:</td>
                       <td>
                           <asp:textbox id="txtElectionName" autopostback="true" runat="server" style="color: #5D7B9D; width: 150px; border-color: #5D7B9D; border-width: 1px; border-style: Solid;"></asp:textbox>
                           
                       </td>
                   </tr>
                   <%-- Election start date here --%>
                   <tr>
                       <td style="color: #5D7B9D;" align="center">Election Start Date:</td>
                       <td>                       
                           <input type="text" id="datepicker" />
                          <%-- <asp:TextBox ID="txtElectionStartDate"  runat="server" Style="color: #5D7B9D; width: 150px; border-color: #5D7B9D; border-width: 1px; border-style: Solid;"></asp:TextBox>--%>
                           <asp:ImageButton ID="ImageButton1" Width="25px" Height="25px" runat="server" OnClick="ImageButton1_Click" ImageUrl="~/Images/cal.jpg" />

                          
                       </td>
                   </tr>

                     <tr>
                       <td style="color: #5D7B9D;" align="center">Election End Date:</td>
                       <td>
                           <input type="text" id="datepicker1" />
                          <%-- <asp:TextBox ID="txtElectionStartDate"  runat="server" Style="color: #5D7B9D; width: 150px; border-color: #5D7B9D; border-width: 1px; border-style: Solid;"></asp:TextBox>--%>
                           <asp:ImageButton ID="ImageButton2" Width="25px" Height="25px" runat="server" OnClick="ImageButton1_Click" ImageUrl="~/Images/cal.jpg" />

                          
                       </td>
                   </tr>

                     <tr>
                       <td style="color: #5D7B9D;" align="center">Adding a Party Start Date:</td>
                       <td>
                           <input type="text" id="datepicker2" />
                          <%-- <asp:TextBox ID="txtElectionStartDate"  runat="server" Style="color: #5D7B9D; width: 150px; border-color: #5D7B9D; border-width: 1px; border-style: Solid;"></asp:TextBox>--%>
                           <asp:ImageButton ID="ImageButton3" Width="25px" Height="25px" runat="server" OnClick="ImageButton1_Click" ImageUrl="~/Images/cal.jpg" />

                          
                       </td>
                   </tr>

                     <tr>
                       <td style="color: #5D7B9D;" align="center">Adding a Party End Date:</td>
                       <td>
                           <input type="text" id="datepicker3" />
                          <%-- <asp:TextBox ID="txtElectionStartDate"  runat="server" Style="color: #5D7B9D; width: 150px; border-color: #5D7B9D; border-width: 1px; border-style: Solid;"></asp:TextBox>--%>
                           <asp:ImageButton ID="ImageButton4" Width="25px" Height="25px" runat="server" OnClick="ImageButton1_Click" ImageUrl="~/Images/cal.jpg" />

                          
                       </td>
                   </tr>
 <tr>
                       <td align="right">
                           <br />
                           <asp:Label ID="lblResults" runat="server" Text=""></asp:Label>
                           <asp:Button ID="AddElection" runat="server" Text="Submit" OnClick="AddElection_Click" Style="color: white; width: 100px; background-color: #284775; border-color: #5D7B9D; border-width: 1px; border-style: Solid;" />
                       </td>
                   </tr>

               </table>
           </td>
       </tr>
    </table>


My DataAccessLayer

C#
public void AddElections(NewElection newElection)
      {
          using (SqlConnection con = new SqlConnection(ConnString))
          {
              SqlCommand cmd = new SqlCommand("AddElection", con);
              cmd.CommandType = CommandType.StoredProcedure;

              cmd.Parameters.AddWithValue("@Election_Name" ,newElection.ElectionName);
              cmd.Parameters.AddWithValue("@Election_Start", newElection.ElectionStart);
              cmd.Parameters.AddWithValue("@Election_End", newElection.ElectionEnd);
              cmd.Parameters.AddWithValue("@Party_Start", newElection.PartyStart);
              cmd.Parameters.AddWithValue("@Party_End", newElection.PartyEnd);
              con.Open();
              cmd.ExecuteNonQuery();
          }
      }


My code behind
C#
protected void AddElection_Click(object sender, EventArgs e)
    {
       String datep = Request.Form["datepicker"];
       String datep1 = Request.Form["datepicker1"];
       String datep2 = Request.Form["datepicker2"];
       String datep3 = Request.Form["datepicker3"];
        
        System.Web.UI.HtmlControls.HtmlInputControl datepickerControl = this.FindControl("datepicker") as System.Web.UI.HtmlControls.HtmlInputControl;



        NewElection elec = new NewElection(txtElectionName.Text, datep, datep1, datep2, datep3);
        elections.AddElections(elec);
        
       Request["datepicker1"].ToString(), Request["datepicker2"].ToString(), Request["datepicker3"].ToString());
    }
Posted
Comments
Nandakishore G N 5-Aug-13 8:42am    
did you debug the code? are you sure you got all the parameters required by the stored procedure?Just debug it once and verify again.

map all the parameters which you are supplying to sp from codebehind.
'@Election_Start' this parameter id different from sp parameter.
 
Share this answer
 
I think in your SP,you are accepting datetime as parameter for Election_Start.So convert your textbox value to datetime and pass that value...
Use
C#
cmd.Parameters.AddWithValue("@Election_Start", Convert.ToDateTime(newElection.ElectionStart));
for conversion and do the same for other params also
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900