Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to execute sql server stored procedure input parameter in asp.net?
    primarykey
    data
    text
    <p>I have a query in sql server as below :</p> <pre><code>Alter procedure testprocedure As Begin select column_date, sum(qty1), sum(qty2), sum(qty3) from table1 End Go </code></pre> <p>I used the code below to access the stored procedure in asp.net. Even i copied this code from another source but it worked for me.</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;script runat="server"&gt; &lt;/script&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head id="Head1" runat="server"&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;h2 style="color:Navy; font-style:italic;"&gt;GridView Example: Execute StoredProcedure&lt;/h2&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:databasename %&gt;" SelectCommand="testprocedure" SelectCommandType="StoredProcedure" &gt; &lt;/asp:SqlDataSource&gt; &lt;asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="true" AllowPaging="true" PageSize="31" BorderColor="Salmon" Font-Names="Comic Sans MS" Width="650" &gt; &lt;HeaderStyle BackColor="IndianRed" ForeColor="Snow" Height="45"/&gt; &lt;RowStyle BackColor="DarkSalmon" ForeColor="Snow" Font-Italic="true" /&gt; &lt;PagerStyle Height="45" HorizontalAlign="Right" BackColor="RosyBrown" Font-Bold="true" Font-Size="X-Large" ForeColor="Snow" /&gt; &lt;PagerSettings Mode="Numeric" /&gt; &lt;/asp:GridView&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Now I altered my query like this for accepting date in parameters :</p> <pre><code>Alter procedure testprocedure @startdate nchar(8), @enddate nchar(8) As Begin select column_date, sum(qty1), sum(qty2), sum(qty3) from table1 where column_date between @startdate and @enddate End Go </code></pre> <p>Please note my date column has data type nchar(8). Now I would like to alter the previous asp.net code posted above to accept this parameter for dates. I don't know to edit the code as I'm very new asp.net and still learning. </p> <p>Error : </p> <pre><code> Could not find control 'textboxStartDate' in ControlParameter 'startdate'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Could not find control 'textboxStartDate' in ControlParameter 'startdate'. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [InvalidOperationException: Could not find control 'textboxStartDate' in ControlParameter 'startdate'.] System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +2106934 System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +50 System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +113 System.Web.UI.WebControls.SqlDataSource.LoadCompleteEventHandler(Object sender, EventArgs e) +46 System.Web.UI.Page.OnLoadComplete(EventArgs e) +9008578 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2350 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload