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

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

do not see auto increment after insert

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :Sql Server

hello all,


i'm a newbee, so maybee a simple question

i have a parent table, with , lets say an id, and another field

i have another table, the child table which uses the id of the parent, for the master-detail relation.

the id is defined as datatype int, allow nulls = no, unique = yes, primary key = yes, identity=true, identityIncrement=1, identitySeed=1

so the id is auto incremented.


i am using ado.net and have a SqlCeDataAdapter, and SqlCeCommand to set InsertCommand

when inserting data and calling the Update() method of the SqlCeDataAdapter, reload the table, i see a nice id.

but, before the table is updated, the Id field is empty, and i would like to see what the id is, because i have also a child table which uses this id.

so, how can i see the id, or how can i add the values to the child, and use a reference (the id or something else) before updating the table ? or is it better to use another technique. I would like to work with the dataset because the data is loaded in memory, and will not save everytime the changes. 

if you know some nice samples, please let me know.

thanks ! andy 


View Complete Post

More Related Resource Links

SharePoint Batch Update Auto Increment Field Value


Hello All,

I am making use of SharePoint List Batch Updating methodology in order to update the items in bulk. I build the query dynamically for each and every item using StringBuilder and process the data ultimately using 'ProcessBatchData' Method.

Now, I have a requirement where I have to increment a particular field value in the query while iterating through each item for building the query. How can I auto-increment a field value for each item in the batch query?


Replication and auto Identity Increment

We want to have two SQL server working on the same data at the same time (SQL Server 2008). I've been told that the auto ID's will stop working (the identity option). I'm not sure how true this is or what is the best replication to use for this.   Thanks

Auto Increment User defined Id

Hi can anyone give me an idea how to create an auto generated id like ED01,ED02 etc., so that when i am entering data the id should be automatically incremented

auto increment date

hi all, I have a table CLRYR with two columns STARTYR,  ENDYR I need to insert value into this these columns as below using a stored procedure STARTYR   ENDYR 1/1/2010 1/31/2010 1/1/2011 1/31/2011 1/1/2012 1/31/2012 i should be able to give the start yr and lets say i have to insert 50 yrs from now. So the values in these columns should add up upto 01/01/2060  01/31/2060 so i will have 50 records with the startyr and endyr. Please help me. thank you.

Custom Contact List: has to be auto-populated with users and manually insert others contact

Hi All, is it possible to create a custom contact list that automatically insert user as contact? I have to use it to send auto-email to the people in the contact list... (ant they can be user or not) Thanks All Vit

SQL auto increment in two tables

Hi, i have a problem with auto increment. I generated auto ID with auto increment, but after this i need to insert new ID to other table. Is possible to generate same ID to both tables? Is possible to do it without select command?

a simple way to auto-increment INT by 1 ?

Hi,   I have a field of datatype INT declared as follows  [barCodeID] int IDENTITY(1, 1) NOT NULL Each time I insert a new record into the table, barCodeID increments by 2, not by 1. Why so and can I make it increment by 1? I also tried [barCodeID] int IDENTITY(0 , 1) NOT NULL which produces exactly the same result, so what the first digit(seed) actually defines ? Thanks -- as you can see I'm a complete newbie

auto increment of primary key which is varchar


hi everyone ...

i  was given a form in which empid is varchar  and i m supposed to auto increment it using a  function and calling it ....

i have never done this. plz help me out the way .

auto increment column in SQL View



Can you please show me what is the syntax to add an increment column to Select Query? There will be additional column which goes 1,2,3 ... n. 

Document ID auto increment


I have a standard document library that I'm adding documents to.  I would expect that the 'ID' property to auto-increment by 1 each time I upload a document, but the column is being incremented by 5.  Is this a setting I can change somewhere to have it increment by 1 instead?  Thanks.

Auto Increment not right after delete and inser


 After i delete a row and then insrt a new row the auto increment row wont assign the correct next number , for example i have


1 last first

2 last first

3 last first

after delete

1 last first

2 last first

after insert

1 last first

2 last first

4 last first


i need some help fixing this, any help would be great thanks

T-SQL how set identity seed on auto increment +1


hi everybody

I have stored procedure where i am creating table and setting primary key how to set auto increment ?

set @sql =@sql + 'CONSTRAINT [PK_'+@Table+'] PRIMARY KEY CLUSTERED ([ID] ASC)) ON [PRIMARY]'

Thanks for any idea

How to Create Auto increment Request number for browser enable infopath form field Programmatically?

hi all,

i have created an infopath which have one request no. field and it will auto increment when click on add new item on sharepoint Document library

field contains (highest value of column request no. +1 )  when infopath will open in browser.

What i have done on this:i have create new data connection on sharepoint library and then pick document library then choose ID field and insert function in the field max(ID)+1.

help me



Insert value using Table Value Functions

a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.

Insert Rows with a GridView

In ASP.NET version 1.x, I used the footer on the DataGrid control to insert new rows by placing a series of TextBox, DropDownLists, CheckBoxes etc. controls on it and then handling a save button. This also works with the GridView in version 2.0 but with one major exception: if your data source is empty, the GridView will hide your footer (and header) and only display the EmptyDataText.

SqlCommand.ExecuteNonQuery() returns -1 when doing Insert / Update / Delete

Sometimes you end up with a return value of -1 when using the SqlClient.SqlCommand.ExecuteNonQuery method.

Why is that?

Well, the ExecuteNonQuery method is there for statements for changing data, ie. DELETE / UPDATE /INSERT, and the returned value are the number of rows affected by that statement.

When checking the documentation we can see that there are some conditions that return -1.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of

rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

Increment div id in a repeater


How can i increment a div id each time a new item is created in a repeater?

Like :

First div item =

<div id="GoogleMap0" style="width: 500px; height: 300px; text-align: center; border-color: Black;"></div>

Second div item =

<div id="GoogleMap1" style="width: 500px; height: 300px; text-align: center; border-color: Black;"></div>

and on.....

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