DataSource Controls :: Getting The PK ID Of The Newly Created Record After Inserting A New Record?
Dec 20, 2010
I am creating an album using the following stored procedure, which returns the primary key for the newly created record:
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE PROCEDURE [dbo].[fpa_sp_albums_update_insert]
@album_name nvarchar (50),
If @album_id > 0
album_img_cover_id_FK = @album_img_cover_id_FK,
album_creation_date = @album_creation_date
Where ((album_id = @album_id))
INSERT INTO [fpa_albums] (
I execute the above stored procedure using the SQLHELPER. The VB.NET code for the page is as follows:
However, the createdAlbumID always shows -1 instead of the id for the newly created album.
I am using a FormView to populate data, then inserting it using a LinqDataSource. The primary key is an autoincrementing identity. I'd like to handle the ItemInserted event to update some other tables, but I cannot find how to get the primary key of the newly inserted record. The insert happens fine, but nothing for the PK.
I realize I can change to using a SPROC, or change to creating the new row and doing the insert myself, but I'd prefer to continue with the LinqDataSource's automatic insert.
Im trying to get the ID out of the record that i'm inserting using scope_identity. I've add the following line of code to the Insert statements in the sqldatasource - SET @insID = Scope_Identity() I've add the following line to the Insert parameter list
I have the logged-in user's Guid stored in a session variable. My understanding is that when the Guid is passed to the session variable it becomes a string. When I use the detailsview control I have to convert the session variable back to a guid and I've been doing it like this and it seems to work fine:
e.values("UserId") = session("LoggedInUserId") Dim UserId as Guid = New Guid()
When I try to use the Insert() command after the following:
I get an "InvalidCastException" error with the comment "Conversion from type 'Guid' to type 'String' is not valid." I'm assuming the session variable needs to be converted to a type Guid since that's what I've had to do with the Detailsview control. I've tried a few different ways of converting the session variable back to a Guid so the insert command will work, but no matter which method of conversion I try I get errors such as "value of type system.guid cannot be converted to 'string'. I'm confused because I thought I was supposed to convert it from a string to a Guid. The "UserId" parameter is a non-primary key uniqueidentifier in the database.
I am in a serious trouble right now, i wanted to know that how to write a query in LINQ to SQL to retrieve identity column's current value before inserting any value.
I need this cos i m building a windows app n i need to display this value before inserting a record. I have tried DataContext.ExecuteCommand('DBCC CHECKIDENT (Tablename)') but it returns the number of rows modified.
i have a table with the following columns; [Id] [CreatedDate] [Title] [Description] the data type for the column [CreatedDate] is Datetime. What i want to achieve is, i want a query that can retrieve records in that were created in the past 24 hours.
The functionality I want to achieve is that when isHomePageFeatured is checked then this record is set to 1 for that column and for all the other records in the table it is set to 0.
This is fine for update as I can use the property Id to compare against, but for the newly inserted record it doesn't yet have a propertyId so I wondered if using newID() to affect all other records would have the same affect.
after a DetailsView (DV) 'Insert' (triggered by a DropDownList (DDL)) the DV shows the first record (in the DDL)!Are there VS2008 means to keep / show the just entered data - again ready with the command row "Edit/Delete/New" enabling me to e.g. "Edit" the just entered data?This DDL/DV scenario works just fine but to show my just entered record I have to leave this page and start calling this .aspx page again in order to see the name in the DDL and, hence, in the DV.I.e. I'm looking for a kind of automatic 'postback' bringing my just entered data back
I have a DetailsView using a LinqDataSource. I have it connected to DropDown so the user can select a record to edit. This configuration works. However when I add a record after I enter the data and press insert link the DetailsView reverts to another record. How can I make the DetailsView stay on the newly added record?
I thought this would be easy before I started, but I should've known better.
I just need to get the value of primarykey from the newly inserted record so I can pass it in the query string to the next page the user will be directed to.
Here's my code:
I had found what looked like a good soultion yesterday by the moderator "ecbruck" at this post:
[URL], but after spending many hours trying to figure out why I couldn't get it translated and working in my own project, I found that MS Access does not allow use of an Output Paramter. And unfortunately I don't have time to teach myself a new database platfrom and am stuck with MS Access for the moment...teaching myself asp.net has my head spining enough as it is.
I've editing a create user wizard to add a 2nd step, this step will collect the users address. i can't get the second step to save into a table. I'm completely new to visual web developer, so if you reply please make it as jargon free as possible, see source code and vb code, i think i'm missing code for the "finish Button click"
Source code is. [Code]....
Code Behind the wizard control Partial Class Registration Inherits BasePage [Code]....
I have a GridView1 With Paging allowed, PageSize = 10. And a Nested GridView2. The INSERT function on nested GridView2 works well until the number of record is 10.
On inserting the 11th record, the GridView1 is recorded normally in page 2 of 2. The Nested GridView2 does not fired properly. it appears empty on the 11th record (page 2 of 2), but instead add its record on the last recorded ID on page 1 of 2.
When I remove the paging, everything works well.
How to resolve the paging issue with Nested GridView on "INSERT" record?
I have a formview and inside it there are two textboxes taking integer as input.I put a condition that if both textboxes are empty then user should be notified that "Please put value in any one of the textbox".It is working very fine.From database side DBA checked that if user input any integer value in any one of the two textboxes and if it is already found in database then there is no insertion.The problem is that everything is working fine and i checked in the database that the record is also not inerting due to duplicate check but user is getting message that "Record inserted successfully."How to stop this message and how to notify user that you have entered duplicate value and transaction should also not been done. Means all inputs should be there rather than clearing textboxes that could be done when "Record Inserted." [Code]....
On inserting record, I want to check that for example if a user enters a telephone number for any record is already in the database then it should validate that the number already exists in table and you cannot enter a duplicate value.
Then if user will provide some other telephone number then he allows to insert record.
For insertion of record I used ObjectdataSource.
User will enter telephone number in a simple textbox.
I may want to inform that I am working in asp.net2.0 and also not allowed to use any third party control or ajaxtoolkit.
I am having trouble changing page numbers on my gridview after deleting a record if the deletion of the record causes there to be no more records on that page. Currently I have a form below the gridview that adds a record to the datasource of the gridview.
Code behind stuff:
Now with this code above, if I insert a new record using the form below the gridview, it will reload and go to the new page if the insertion causes the record to appear on a new page, however when I delete that record, thus causing nothing to be on that page, the gridview visually just dissappears. I've got the gridview bound by a linqdatasource control, and on the page_load function I only databind if the page is not a postback.
I have a delete button bellow my gridview and I want a pop up to show when no record is selected and tell the user to first select a record. The button click event would show the pop up, but my gridview data blanks out.