Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I have a field that is autoNumber, automatically incremented by the database.

 

Each time you add a row and cancel the edit or the addition is rejected by the database, the number gets incremented again even if no row has been added.

 

I used to have a different set of control for input and did all the checking before i added the row to the database.(double work since i already defined the constraints in the DB)

I'd much rather have the DB do the checking and return me the error...

 

So how can I refresh the increment?

Edited by Ariez

Auto-suggestion: "I have a life"

Uncontroled thinking: "So what the.."

Posted

Its just a dataset filled with this Access table where the primary key is AutoNum.

I linked the dataset to a datagrid.

each time i go to a new row (where the * is) I get the autonum +1 even if i didn't keep the row...

 

So i'm still local here, I havent posted the changes to the DB yet...

(Good link though...i kept it)

Auto-suggestion: "I have a life"

Uncontroled thinking: "So what the.."

  • *Experts*
Posted

I don't believe there's any easy way to keep the number that was temporarily used if you rollback. I know in SQL Server you have the ability to turn off an Identity column temporarily, but I've never wanted to use it the way you mean to AND you'd have to keep track of what the number *should* be so that you could reset the seed.

 

I can understand from a "clean" perspective why you'd not want the number of increment, but from a usability standpoint there's no reason why having the numbers out of sequence should cause any problems. Are you relying on the number to always be sequential? If so, and you have the ability to rollback trans and get the number out of sync, you'll want to use a separate table to control the sequence.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Yes, I need every line numbered carefully, it's just accounting requirements.

But you gave me a direction for searching:"turn off an Identity column temporarily"

Thanx...

Auto-suggestion: "I have a life"

Uncontroled thinking: "So what the.."

Posted

If you're just looking to retrieve the autonumber as you add the row (and I know this looks wierd), you can do it thusly:

 

Dim thisPrimaryKey As Integer = ds_MyDataSet.MyDataTable.AddMyDataTableRow(MyRow).ID

"It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve."

 

- Edgar Allan Poe, 1841

 

I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker.

 

- Helen Keller

Posted
Yeah, you know i'm glad you said it because this was my conclusion too...

Auto-suggestion: "I have a life"

Uncontroled thinking: "So what the.."

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...