.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Last Inserted Id

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :ASP.Net

I'm always getting '-1' as return value from my business layer insert method. Why?

View Complete Post

More Related Resource Links

how to get id value from the row inserted in a table with thr trigger.


I have a reports table with column report id and and report version. I created a trigger on this table to execute an application to do some processing each time a row is inserted in reports table. I need to pass the new report id execute this application from the trigger. How do I get the report id from the row that was inserted?


get the last inserted row ( autoincrement id ) in mysql database back


In my mysql I have an autoincrement id , whenever I add a new row into database I need to store this id in other table, so how to get this autoincrement Id back?

Display last inserted column value in the Form and concurrent updates


1) I have a ORDER form which is a usercontrol(webpart in sharepoint)

    the first field is a autogenerated column given as ORD01,ORD02,ORD03...

    for this i have a column in the list which stores these values into list after user submits data.

    Now i want to show last inserted ORDER + 1 in the first field .

    i.e., when user opens this ORDER page it should show the value.

2) the second case would when user submits data simultanoeusly.


Can anyone suggest a solution for this



Triggering an event to occur within a VB.NET app if something is inserted into an SQL Server table

Let's say SQL Server is inserting arow within a table. Is there a way to let VB.NET know that an event was fired (being the inserting of the row within the table), without the need to query anything. Bascially having SQL Server tell the VB.NET app that an event was fired. It seems like it might be possible using CLR and the .NET framework integration wthin SQL Server, but I haven't found a sample program showing what I'm attempting. I understand that this topic covers SQL Server and VB.NET.  This need being for both and this forum only set for SQL Server, I thought I'd take the risk and post in this forum. Thank you in advance for any assistance.Newbie

display icon or colum for inserted file in infopath form

i have a list with infopath form and in this form i have insert file now i need naythin in the view say there is attached or insert file in this record like the icon for attachment or column display file name or his path ,somthink can i know in this record there is attachmentThanks for any help :) my blog is: http://www.waelk.com

C# .NET SqlBulkCopy inserted row count

Im using a Script task to extract data from Oracle into SQL Server using SqlBulkCopy. I need to get a count of rows inserted by the SqlBulkCopy and cant figure out how to do this. I did try the SqlRowsCopied event, but it looks like I need to fill the NotifyAfter property to get the SqlRowsCopied to fire. I am confused because if I have say 11 rows in the source, and set the NotifyAfter to 100 it doesnt fire. If I set the NotifyAfter property to 10, then the event fires and I get the count of 10 and not 11 (however, 11 rows get inserted). Is there an efficient way to get the RowsCopied for the SqlBulkCopy?  ThanksYou are so wise...like a miniature budha covered in fur. -Anchorman

output inserted sql server 2005

Hi, I have to insert multiple rows into one table and get the ids into another table. declare @noticeoutput table (InfoID BIGint ,InfoDetails VARCHAR (MAX),orderid nvarchar(100) ) INSERT INTO [NoticeInformation] ([information_details] ,[information_date] ,[information_done] ,[notice_id]) OUTPUT inserted.information_id,inserted.[information_details],@ItemId into @noticeoutput select @ItemId + ' Customer:' +@Shiptoname + ' Value: '+@value ,getdate() ,0 ,@notice_id from #NewPL     INSERT INTO [TasksActionData] ([information_id] ,[Data]--order ,[ActionId]) select distinct InfoID,@ItemId,5 from @noticeoutput outp inner join [order] o on o.order_id=orderid inner join billto on o.billto_id=billto.billto_id   The output in noticeinformation table is: Information_id Information_details 111739   PL: 9900006244 111740   PL:9900006245   The current output in Tasksaction data which is incorrect is:   ActionDataId Information_id Packlist_id Actionid 12437930 111739 9900006244 12 12437931 111739 9900006245 12 12437932 111740 9900006244 12 12437933 111740 9900006245 12  The desired outcome: ActionDataId Information_id Packlist_id Actionid 12437930 111739 9900006244 12 12437933 111740 9900006245 12 Ho

How can you use Linq to SQL to get the primary key of a record you've just inserted?

Hi,I'm inserting data into a database with Linq to SQL and would like to access the primary key of that record WITHOUT doing a query for the values I've already captured.Here is my insert startment: Dim page As New pageData With {.pageTitle = txtPageTitle.Text, .pageDescription = txtPageDescription.Text, .pageContent = HttpUtility.HtmlEncode(txtPageContent.Text) }There is a value in the table that is an auto increment integer.Rather than doing a query for the pagetitle, description and content I'd like to just access the primary key that I would have just generated by performing the insert.Is this possible or would I have to perform the query as I've just mentioned to retrieve it?

Display Inserted Record After Insert Using A FormView

How do I display a record in a FormView once the record has been inserted? I'm able to get the Identity of the new record without anyproblems, but I can't figure out how I should code the _ItemCreated event. Protected Sub FormViewMessageDetail_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) 'Refresh the list to show the new record RepeaterMessages.DataBind() 'Set the .SelectCommand to Select the New Record SqlDataSourceMessageDetail.SelectCommand = "SELECT * FROM Messages WHERE [Id] = " & NewId FormViewMessage.DataBind() FormViewMessage.ChangeMode(FormViewMode.Edit) test.Text = NewId.ToString End Sub Protected Sub SQLDataSourceMessageDetail_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) NewId = e.Command.Parameters("@NewId").Value End Sub

special character wrongly inserted

I have a gridview with checkbox column.  I loop through all the rows of gridview, if it's checked I enter the second column text into my database.The second column text at one point shows the word  Küche, but when I take that text (in order to insert it in db) it gives me Kücheand that's what I see when I then read it from db.

Get inserted ids when inserting from User Defined Table Type

Imagine this procedure:   CREATE PROCEDURE [dbo].[insertActive] ( -- Add the parameters for the stored procedure here @p_data dbo.activeUpdate readonly) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. insert into dbo.active (name,stateid) select name,stateid from @p_data END How can I get the ids of the rows that have been inserted?  I tried searching the net and the forums but could not find anything. Thanks for any and all help, Gareth.

Item Not inserted into sharepoint list via web service.

Hi all, I am developing a silverlight application. In that application I want to insert data into sharepoint list using Lists.asmx web service. I am retrieving data from grid view and storing data into sharepoint list using method  UpdateListItemsAsync(). But some time all the data from all the eight grid view rows get inserted properly, whereas some time only for rows get inserted, sometime only three. I am not understadding this asynchronous behaviour. Can anyone explain what I have to do to insert all eight rows every time. Thanks,   -Kaustubh

Delete records if it is not getting inserted and also in the related tables

Hi All, If the insert into table person is successful, but the insert into table subject fails, delete the person record and all records associated with the person that were also inserted. If the insert into table person is successful, and the insert into subject is successful, but the insert into the booking table fails, delete the subject record, the person record ,and all records associated with the person that were also inserted. The reason for the failure into the 3 tables (person, subject, booking) should be logged to tblErrors . Also, a message should be written to tblErrors which logs the fact that this situation has occurred.     -- I have few stored procs which does inserts and updates How would i capture the record which is not getting inserted and log in to log table and delete the previous records which got inserted  which are related to that.

Possible bug: Calendar views browse month function not working when list is inserted as webpart.


Inserted a custom list with a calendar view on a page as webpart. Browse month function does not work, there is a postback but month is still the current month instead of the next or previous.

Is this a know issue/bug?

URGENT :Deleted Vlues to be inserted in new table


HI, I need some help from you guys ...Please


My requirement is

I have a database called DB






---(i will have 8990 Customer)IDs




and here i have to store the deleted results it in a new physical table ...but here is the issue


Dependent Tables:  Fullfiullement( Customer_ID,Order_ID,Phone))



etc etc

dependent or referencing other tables ..so i have to DROP the Child table first with taking the Customer _ID and order_IDs from above ...



SO i need to write a Script which will delete the Child tables and then Parent tables and i have to Save each deleted tables Data ........

I will  have :Customer_ID   


---(i will have 8990 Customer_ID )



and i need to delete only the records of those customer_IDS

Getting last inserted record


Dear all,

I am executing the following queery snipet from a  store procedure :


 In the same procedure I would like the lst record inserted by unsing the Identity field

Deos "Select MAx(ID) from [dbo].[PLAYERS_HISTORY]" will always return the last inserted row ?

ID is the identity column


Your knowledge is enhanced by that of others.

C# string has CRLF inserted @ 1024 interval


I use the following to test in VS2005, VS2010, Winform and WebForm and I got the strange result of a string with a CrLf inserted at 1024 intervals. Anybody has any idea?

When I use this to construct <html>, if the CRLF falls in a <td > then it;'ll break. I also tried to use string builder, same effect.

            s += "0123456789";

         string s = "";

         for (int i = 0; i < 300; i++)


            s += "0123456789";


set a break point after this and display ?s at th ecommand window and cut the strin gto Wrod ir any editor that shows EOL markers and the CRLF is there???

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend