none
"Add New Data Source..." in "VS Team System 2008" and it's unexpected behavior RRS feed

  • Question

  • 1. Create following table named x in SQL Server
    CREATE TABLE [dbo].[x](
    
    
    
    [id] [int] IDENTITY(1,1) NOT NULL,
    
    
    
    [text] [nchar](10) NOT NULL,
    
    
    
    CONSTRAINT [PK_x] PRIMARY KEY CLUSTERED 
    
    
    
    (
    
    
    
    [id] ASC
    
    
    
    ) ON [PRIMARY]
    
    
    
    ) ON [PRIMARY]
    
    
    
    
    
    
    
    

    2. Add New DataSource from this table and Drag&Drop it on a Form. 

    AutoIncrementStep and AutoIncrementSeed are -1 but must be 1 according to database


    With best regards, Yasser Zamani
    Sunday, December 6, 2009 5:23 AM

Answers

  • As I pointed in my previous post, by default, DataTable does NOT use rules of the database to create identity values. DataTable is completely database independent and has no idea about identities in underlying database. It maintains it's own set of identities for newly created rows and, by default, they are ALWAYS negative and that is correct behavior. If you want to have same rules for the identities as in your database than you could set AutoIncrementStep and AutoIncrementSeed properties to use same rules as in database, but during updates, you may get into conflict of the identity values, since positive identities generated in a DataTable may already exist in database, and it could lead to some update errors. Following article provides an additional details about how identity values work with the DataTables 

    http://www.akadia.com/services/dotnet_autoincrement.html


    Val Mazur (MVP) http://www.xporttools.net
    Tuesday, December 8, 2009 11:13 AM
    Moderator

All replies

  • Do you refer to the properties of the DataTable in a code? It is correct behavior in this case, since DataTable maintains it's own identity values locally and, by-default' they are negative numbers starting with -1. When DataAdapter stores newly inserted rows from a DataTable into the actual database, then database will generate real identity values.
    Val Mazur (MVP) http://www.xporttools.net
    Monday, December 7, 2009 11:18 AM
    Moderator
  • Do you refer to the properties of the DataTable in a code? It is correct behavior in this case, since DataTable maintains it's own identity values locally and, by-default' they are negative numbers starting with -1. When DataAdapter stores newly inserted rows from a DataTable into the actual database, then database will generate real identity values.
    Val Mazur (MVP) http://www.xporttools.net

    Hi VMazur,
    First take a look at realated .xsd file by double clicking it in solution explorer then find the id column in x table. you see in this column properties page that AutoIncrementStep is -1 but it must be 1 according to the database.
    Also if you insert some new rows in related DataGridView directly you will see id starts with -1 and then -2, -3, ..., -n but must starts with 1 then 2, 3, n again according to th database.

    With best regards, Yasser Zamani
    Tuesday, December 8, 2009 8:37 AM
  • As I pointed in my previous post, by default, DataTable does NOT use rules of the database to create identity values. DataTable is completely database independent and has no idea about identities in underlying database. It maintains it's own set of identities for newly created rows and, by default, they are ALWAYS negative and that is correct behavior. If you want to have same rules for the identities as in your database than you could set AutoIncrementStep and AutoIncrementSeed properties to use same rules as in database, but during updates, you may get into conflict of the identity values, since positive identities generated in a DataTable may already exist in database, and it could lead to some update errors. Following article provides an additional details about how identity values work with the DataTables 

    http://www.akadia.com/services/dotnet_autoincrement.html


    Val Mazur (MVP) http://www.xporttools.net
    Tuesday, December 8, 2009 11:13 AM
    Moderator
  • As I pointed in my previous post, by default, DataTable does NOT use rules of the database to create identity values. DataTable is completely database independent and has no idea about identities in underlying database. It maintains it's own set of identities for newly created rows and, by default, they are ALWAYS negative and that is correct behavior. If you want to have same rules for the identities as in your database than you could set AutoIncrementStep and AutoIncrementSeed properties to use same rules as in database, but during updates, you may get into conflict of the identity values, since positive identities generated in a DataTable may already exist in database, and it could lead to some update errors. Following article provides an additional details about how identity values work with the DataTables 

    http://www.akadia.com/services/dotnet_autoincrement.html


    Val Mazur (MVP) http://www.xporttools.net

    OK,
    In your words, if i set AutoIncrementStep and AutoIncrementSeed to -1 in database too i may get into conflict of the identity values.
    Is this conflict a bug?
    With best regards, Yasser Zamani
    Tuesday, December 8, 2009 3:37 PM
  • No, this is not a bug. This is done to avoid conflicts and if you read the article, it explains it.
    Val Mazur (MVP) http://www.xporttools.net
    Wednesday, December 9, 2009 11:01 AM
    Moderator