View Inserted Record Using Object Datasource, Details View and Stored Procedure

I am trying to display the record just inserted into a database using an object datasource, a stored procedure and a details view

Below is the stored procedure
ALTER PROCEDURE [dbo].[Employees_Insert]
 @LastName varchar(50),
 @FirstName varchar(30) = null,
 @JobTitle varchar(50)
INSERT INTO [dbo].[Employees] ([LastName], [FirstName], [JobTitle])
VALUES (@LastName, @FirstName, @JobTitle);
SELECT  LastName, FirstName, JobTitle
FROM Employees


The insert parameters for the object datasource are below

<asp:ObjectDataSource ID="EmployeessDataSource" runat="server"  InsertMethod="AddEmployee"
        OldValuesParameterFormatString="{0}"  SelectMethod="GetEmployeeByEmployeeID"
        TypeName="EmployeesBLL" UpdateMethod="UpdateEmployee"
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="LastName" Type="String" />
            <asp:Parameter Name="JobTitle" Type="String" />


The method to add a new employee is below
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
    public bool AddEmployee(string FirstName, string LastName string  JobTitle)
        // Create new row instance
        WirelessDataSet.EmployeesDataTable deviceOwners = new     WirelessDataSet.EmployeessDataTable();
        WirelessDataSet.EmployeesRow employees = employees.NewEmployeesRow();

        employee.FirstName = FirstName;
        employee.LastName = LastName;
        employee.JobTitle = JobTitle;
        // Add new individual device owner
            EmployeesTableAdapter ta = new EmployeesTableAdapter();
            int rowsAffected = ta.Update(employees);
            //Return true if exactly 1 row was inserted, otherwise false
            return rowsAffected == 1
        catch (Exception ex)
            throw new Exception(ex.Message + ' ' + ex.InnerException);

    } // end method


I'm not sure what I need to change in order to display the newly inserted record in the details view.  Thanks for your help.

9/11/2008 4:44:45 PM 72751 articles. 3 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 13
Get it on Google Play
Get it on Apple App Store

 You should return which is your primary key instead of bool as return value and use that id to retrive the record in datatable and databind it to datacontrol. Smile


9/11/2008 5:01:58 PM

Sorry I am a total newbie.  I'm not sure how to get the value of the employee ID that was just inserted.  Can you tell me how I would get this value?  Thanks.

9/11/2008 5:22:48 PM

Sorry - I got it now.  It took me a few minutes to digest it.  Thanks for your help!

9/11/2008 5:29:03 PM

Similar Artilces:

Call stored procedure inside a view (or) Use EXEC inside a view (Or) Use EXEC inside a function
Hi, All the stored procedures in our application are using a single view for data fetching from the DB.  That view contains a single select statement which fetches 2 columns from a user defined function.  We have a separate table (Say XXX) where we stored some sql queries and a flag.  Now based on the user logged in to the application we have to select some queries from the XXX.  Based on the flag column of XXX we have to UNION the result set of some queries with the view and EXCEPT the result set of the queries from the view.  What we plan is, we can create a strin...

can't get records to update using grid view control or details control
Hi  I am using Visual Studio Web Developer 2005 Express and have set up a web page with a Grid View.  Everything works great, but when I click the EDIT link and make a change to a field, and then click UPDATE, it returns to the normal grid view form, but the change has not been made ??  I have the same proble using the details view object.  I do not get any errors, but the changes just do not seem to be made to the SQL table data. Any help would be greatly appreciated !   Thanks Chuck Hi Chuck, Can you verify you have DataKeyNames set in your GridView...

Inserting records using the details view or programmatically
I'm a new user to vwd.  If I use a details view control on my page, I have noticed that the "New" link is not visible unless there is at least one record in the table. Is there any way of making it visible where there aren't any records?My web pages are currently hosted at vwdhosting. I have uploaded my database with the record structure onto the web site and I am using a remote connection string to access it. I have had users updating data in another table on the remote database. If I add records to my new table locally and upload the database to the remote site, all ...

How to Insert,Update,view the record using Form view from code behind?
Hi,I have a listbox and dropdownlist in the formview.How do i bind them to the database and show it in the webform?I m not adding list inside them using wizard.i m using code this:-listbox1.items.add(textbox1.text);how should i approach this?thanks.jack.       I think you are using ADO to bind your data, so you need to extract a reference to your controls from within the FormView.DataBound event. Here, you can databind your controls as you need. Then you can use a data-binding expression within the SelectedValue property of your controls so that th...

How to make the width of Detail View control consisten when updating, viewing or inserting data?
I have a DetailsView control on my website, and I notice when I edit, insert or simply displaying a record, the width of the fields vary. To make them consisten, I converted all of the fields to templateField, and had to change the 'width' property for each field within each template (ItemTemplate, EditTemplate, InsertTemplate). Is this the best or most efficient way of standardizing the DetailsView field widths? Perhaps there is a way to simply state the width once and all fields within DetailsView will inherit that value?Thanks, for more granular control over your detailview layo...

how i use details view control to insert ,update and delete
How i use detalisview control to insert records into database , but i want to insert recods not with using sqldatasource control i  am retreving id from the one method and i am using this id to inset and update delete records in database.adilahmed Here's a CRUD example for a DetailsView using ADO: ASPX <%@ page language="C#" masterpagefile="~/MasterPages/Default.master" autoeventwireup="true" codefile="CRUDWithADO.aspx.cs" inherits="DetailsView_CRUDWithADO" title="DetailsView_CRUD With ADO" %> <asp:co...

Insert To Multiple Tables Using Details View Control
Dear All,   I am using a Details View Control to do some Data Entry, On the Insert of the Details View Control, i Need to Insert the Values into Two Different Tables and also do an updation to a Different Table. Currently i have the below copied code there.. how can i modify it to add one more table for insertion and one table for updation <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Freight.mdb" InsertCommand="INSERT INTO [Product Receiving History] (ReceiptNo, ReceivingDate, ReceivingReference, SupplierN...

grid view and detail view with drop down box in the detail view.
I have grid view control and detail view control.  When the grid view control select edit, the detail view drop down list will have the current value. Also it have have selection .  dropdow list will have F, M. See the code below.  Thanks.     <body> <form id="form1" runat="server"> <TABLE style="FONT-FAMILY: arial" cellSpacing=0 cellPadding=0 width=100% align=left border=0> <TR align=center ><TD style="HEIGHT: 20px" borderColor=#000080 align=center width=960 bgColor=green colSpan=3...

Details View Insert not displaying inserted record
I have a DetailsView control that is working fine.  It is inserting the rows the way I expect but I would think the DetailsView would show the most recently added row.  In fact the behavior I am getting is that the first row is displayed after the insert is completed.  It seems to me that a normal behavior would be for the control to show the recently added record.  Is there a property I can set to make the control behave this way?  Is there a way I can interrogate and use the key for the recently added row?  The key is an identity column so I don't have a value...

Error Binding Listbox Using Stored Procedure: Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).
Error when binding Listbox Using Stored Procedure: Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).If I removed the stored procedure and enter the same query that is in the stored proc it works fine.  If I bind the control manually to the stored proc it works fine.  What am I missing? This Fails with the error:<asp:SqlDataSource                 ID="sqlDsTopics"                 runat="server"     &n...

Use Stored Procedure or insert template to insert a new record?
Hi there, I am using stored procedure for all my database website before I use .net 2. When I come to .net 2, I found almost all the videoes are using SP for select functions, and using insert template to add new ones. What's the differenence and which way is better? Thanks!  >which way is better?Whenever you can, use stored procedures - preferably your own, not some of the autogenerated horrors! If you want some help in generating them - see my post in plus the helper bits in

Master/Detail Form using Gridview and Details View controls
There are useful codes in the following page: Introducing the ASP.NET 2.0 GridView and DetailsView Controls used code under Listing 12. Creating a Master/Detail Form and everything worked fine. But when I clicked the master record to view the details I am getting a server error message "Cannot find column [@EmployeeID]" Where did I go wrong? Can anybody clarify?...

details view within a details view?
hi i was wondering how to bind data to a details view that is already inside a details view? btw i am using code behind datasource you can use the outer detailsview pre_render event, and there by using findcontrl() method you can find the inner detailsview. then assign the datasource to it. and bind the data to it.protected void DetailsView1_PreRender(object sender, EventArgs e) { DetailsView dvInner = (DetailsView)DetailsView1.FindControl("dvInner");  // here dvinner is the id of the innerdetailview specified in itemtemplate of the outer detailsview dvInner.DataSource =...

Using Linq to update records using a dropdown inside a Details view
 I am using a Details view to update records and which uses a dropdown instead of the usual textbox The ddl is populated through another Linq Datasource whcih gets its data from another table. The problem here is that I am unable to bind this ddl to the data field to be updated since the record's field contains null by default, which doesnt match with the ddl's value field. The error it gives is like this:- ''Couldn't bind the selected value of the record to the value of the ddl" I tried using the foll. "Bind("Field2")==null?"":Bin...

Web resources about - View Inserted Record Using Object Datasource, Details View and Stored Procedure -

Datasource - Wikipedia, the free encyclopedia
A DataSource object has properties that can be modified when necessary. For example, if the data source is moved to a different server, the property ...

Inverness Graham Acquires DataSource
Inverness Graham , a lower middle market private equity firm headquartered in suburban Philadelphia, has acquired DataSource , a print supply ...

SmartGlance for iPad for iPad on the iTunes App Store
Read reviews, get customer ratings, see screenshots, and learn more about SmartGlance for iPad on the App Store. Download SmartGlance for iPad ...

Chaitanya Pandit (@chaitanyapandit) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Data source - Wikipedia, the free encyclopedia
... Data source A data source is any of the following types of sources for (mostly) digitized data: a database in the Java software platform, datasource ...

2ndQuadrant - PostgreSQL expertise from specialists with a source code level understanding of RDBMS ...
PostgreSQL expertise from specialists with a source code level understanding of RDBMS PostgreSQL Planets Gabriele’s PlanetPostgreSQL Gianni’s ...

Tagged entries for CLOUD COMPUTING
Alan Williamson's output as a Java Champion, Blog-City Architect, BlueDragon Creator, Author, Speaker and Internet Guru

Private equity deals
... of biometric identity management systems, applications and services. Inverness Graham Investment has acquired DataSource ...

C# C Sharp and Tutorials on C#
Learn the c# langauge to build web applications using our online tutorials with live demos. Participate in our forums and learn from others. ...

JavaScript UI Library, Ajax Components & HTML5 Framework - DHTMLX
DHTMLX offers a rich JavaScript library, UI components & HTML5 mobile framework. Build impressive web apps for both desktop and mobile devices. ...

Resources last updated: 1/23/2016 9:00:09 PM