Erro updating filtered table

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have a dataset/dataadpter scenario with an access table with auto number
id. The select command has a condition (where clause). The problem is that
when I add a new record, I don't get the highest id +1 in the id field
rather the highest id in the current selection + 1. This creates duplicate
values in id and gives error. What is the way to go around this?

Thanks

Regards
 
Set the AutoincrementStep value to -1. Then Access will assign the correct
value for you and you'll never need to worry about multiple instances
writing the same values...if you want to retrieve the new value that the db
assigned b/c for instance you have related tables, Bill vaughn has a great
article at www.betav.com and David Sceppa has recently discussed this in
this NG. I'll find the post and post it..

HTH,

Bill
 
myDataSet.Tables(Index|"OrName").Columns(Index|"NameOfAutoIncrementColum").A
utoIncrement = true
myDataSet.Tables(Index|"OrName").Columns(Index|"NameOfAutoIncrementColum").A
utoIncrementStep = -1
myDataSet.Tables(Index|"OrName").Columns(Index|"NameOfAutoIncrementColum").A
utoIncrementSeed = 0 .

Setting it to -1 will ensure that you never have a collision so it's highly
recommended.

HTH,

Bill
 
Hi Bill,

Will this happen if the table recognizes the column as the PK, or will that
prevent it, even if the datatable is filtered?

Tx,

Bernie Yaeger
 
Bernie: If I understand your question, then the short answer is Yes, it
will. Since this is a datacolumn, it doesn't necessarily have any
relationship to a database table although it may (and in most instances
does). If you set the .Unique property to True, you've effectively created
a PK out of the column. That won't have any effect on how the Autoincrement
field works and you can still set the incrementvalue to -1 (or negative
whatever). The logic behind using a negative number is that these fields
(Identities in SQL Server or AutoNumber in Access) will not insert a
negative number so the DB will determine the next legal value and take care
of it for you. AFAIK filtering doens't have an effect on this either
although I don't recall doing it on a filtered table off the top of my head.

HTH,

Bill
 
Back
Top