Using ObjectDataSource to run stored procedure with data input by user into web controls

Last post 12-15-2006 12:14 PM by ecbruck. 1 replies.

Sort Posts:

  • Using ObjectDataSource to run stored procedure with data input by user into web controls

    12-15-2006, 11:00 AM
    • Loading...
    • JPortnoy
    • Joined on 08-01-2006, 1:33 PM
    • Posts 39
    I am attempting to have a form where the user inputs data, it verifies the data, and then posts the data into a SQL database using a stored procedure and the INSERT command.

    I need some assistance in using the ObjectDataSource control combined with a submit button correctly. What do I specifically have to do for the submit button to have it use the ObjectDataSource, which links to the stored procedure?

    I have the TableAdapters setup in my DAL, and the function "function_spStoreData" created already.

    I have the following code:

     <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="function_spStoreData" TypeName="myTableAdapters.SetNewValuesTableAdapter">
            <SelectParameters>
                <asp:ControlParameter ControlID="FieldA" Name="MyField1" PropertyName="Text" Type="String" />
                <asp:ControlParameter ControlID="FieldB" Name="MyField2" PropertyName="Text" Type="String" />
            </SelectParameters>
    </asp:ObjectDataSource>
     

    Filed under: , ,
  • Re: Using ObjectDataSource to run stored procedure with data input by user into web controls

    12-15-2006, 12:14 PM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 2:39 PM
    • Des Moines, IA
    • Posts 7,995
    • Moderator
      TrustedFriends-MVPs

    Maybe this example will help:

    ASPX 

    Project Name: 
    <asp:textbox id="txtProjectName" runat="server" /> 
    <asp:button id="btnAddProject" runat="server" text="Add Project" onclick="btnAddProject_Click" /><br />
    <br />
    <asp:gridview id="gvProducts" runat="server" datasourceid="odsProjects">
    </asp:gridview>
    <asp:objectdatasource id="odsProjects" runat="server" insertmethod="Insert" selectmethod="GetProjects"
    	typename="ASPNETTableAdapters.ProjectsTableAdapter">
    	<insertparameters>
    		<asp:controlparameter controlid="txtProjectName" name="ProjectName" propertyname="Text"
    			type="String" />
    	</insertparameters>
    </asp:objectdatasource>
     

    CODE-BEHIND 

    protected void btnAddProject_Click(object sender, EventArgs e)
    {
    	odsProjects.Insert();
    }
     

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter