Link to home
Start Free TrialLog in
Avatar of awilderbeast
awilderbeastFlag for United Kingdom of Great Britain and Northern Ireland

asked on

insert using stored procedure from code behind?

hi all,

i have a simple form that im using to insert a record, on the button "create".onclick

ive added the below

my only problem is i dont know how to pass the parameters and fields to the stored procedure?

 
   protected void butCreatePlan_Click(object sender, EventArgs e)
    {
        dsCreatePlan.ConnectionString = strConnection;
        dsCreatePlan.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
        dsCreatePlan.InsertCommand = "sp_Plan_Insert";
        //?
        dsCreatePlan.Insert();
    }

Open in new window

Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you declared the InsertParameters in the aspx ?

It would help if you posted your aspx code.

If the parameters are declared you simply:

dsCreatePlan.InsertParameters["myParameterName"].DefaultValue = MyTextboxName.Text
Avatar of awilderbeast

ASKER

no there is no code in the aspx, im trying to do it all from the codebehind...
ASKER CERTIFIED SOLUTION
Avatar of angus_young_acdc
angus_young_acdc
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi awilderbeast,
curious why code behind?

I'm a big fan of codeless databinding, just drag a sqldatasource onto the page, right click, choose configure datasource, enter the connection defined in your web.config, choose your stored procedures from the offered lists, do the same for the edit,insert and delete tabs, test the select sproc, click ok. All your parameters will be defined appropriately in the sqldatasource parameters section. Then drag a form/gridview/datalist/whatever on the page, right click, choose the datasource, then configure datasource again, all your formview templates will be created codelessly; take it for a spin. If all works out ok, style up the formview templates for presentation. Code behind should look like:
Partial Class Default2
    Inherits System.Web.UI.Page

End Class

Open in new window

Beautiful, maintainable, scalable, manageble ...
Alan