?
Solved

Insert data in asp.net C# using a stored procedure

Posted on 2009-07-14
3
Medium Priority
?
827 Views
Last Modified: 2012-05-07
Hi I am new to asp.net and c# I am looking to do a simple insert into a datbase using a stored procedure. I have the following code in the front end of my file. Is anything missing from this data source what would the code in the code behind file need to be to execute this stored procedure. I am very new to this so please if possible send me the code.

<asp:SqlDataSource ID="sqlinsert" runat="server" 
            ConnectionString="<%$ ConnectionStrings:PTConnectionString %>"
                 InsertCommand="sp_EventsInsert"
                 InsertCommandType="StoredProcedure" 
                 <insertparameters>
                  <asp:Parameter Name="cid" Type="Int16" />
                  <asp:Parameter Name="EventStartDate" Type="DateTime" />
                  <asp:Parameter Name="EvendtEndDate" Type="DateTime" />
                  <asp:Parameter Name="PatientId" Type="Int16" />
                  <asp:Parameter Name="EventId" Type="Int16" />
                  <asp:Parameter Name="PatientStatusChange" Type="Int16" />
                  <asp:Parameter Name="Reason" Type="Int16" />
                  <asp:Parameter Name="Memo"  Type="String" />
                  <asp:Parameter Name="EventTypeID" Type="Int16" />
                  <asp:Parameter Name="LoginID" Type="Int16" />
                 
                 </insertparameters>
                 </asp:SqlDataSource>

Open in new window

0
Comment
Question by:susan1978
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 24852952
You will probably want to bind this SQL Datasource to either a DetailsView or a FormView control. These controls will take care of the majority of the work.

1) Drag Data component to the form
2) Click the smart tag and select this SqlDataSource as your datasource (smart tag is the little arrow at the top right when the control is selected)
3) Set the DefaultMode to be Insert.

These controls will take care of the code to execute the Insert automatically.
0
 
LVL 13

Accepted Solution

by:
drypz earned 1500 total points
ID: 24856500
Hi! Do it something like this.

    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlDataSource1.InsertCommand = "YourStoredProcedureName";
        SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
        SqlDataSource1.InsertParameters.Add("@Parameter1", DbType.String, "value1");
        SqlDataSource1.Insert();
    }
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question