Articles → ADO.NET → How to call stored procedure using SQL data source in asp.net

How to call stored procedure using

SQL data source in asp.net






Software Requirements







Technical knowledge















Scenario





Create a new table





Click to Enlarge


Click to Enlarge


Create a new stored procedure




Create Proc GetMyTask @TaskId int As 
Select 
  TaskId, 
  TaskName 
from 
  MyTask 
where 
  TaskId = @TaskId



Create a web application and add controls in web form




<%--Controls--%>
<asp:TextBox ID="txtTaskId" runat="server"></asp:TextBox>
<asp:Button ID="btnTest" runat="server" Text="Click" />
<%--GridView--%>
<asp:GridView ID="gvTask" runat="server"></asp:GridView>





Add SQLDataSource in the web form




<asp:SqlDataSource ID="source" runat="server" ConnectionString=""
        SelectCommand="GetMyTask" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="txtTaskId" PropertyName="Text" Name="TaskId" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
<%--Controls--%>
<asp:TextBox ID="txtTaskId" runat="server"></asp:TextBox>
<asp:Button ID="btnTest" runat="server" Text="Click" />
<%--GridView--%>
<asp:GridView ID="gvTask" runat="server" DataSourceID="source"></asp:GridView>





















Output





Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Saturday, July 12, 2014

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250