Problem with AutoNumber key column

Hi,

I'm using dataGridView in VS 2005 environment.

And I observed that the AutoNumber key columns increments the number whenever I sort on the grid.

Scenario to reproduce the problem is:

-bind the grid with 'Employee' table.(EmployeeID column is Primary key and it's AutoNumber)

-Sort on the gird.

Observe: EmployeeID column displays different number at each time when we sort the grid.

Any idea about this

Any comment is appretiated.

Thanks.

Julia168



Answer this question

Problem with AutoNumber key column

  • kmax

    Hi Adamus,

    I've sent avi file to ur adam.turner@getpaid4spam.biz mail.

    Plz check this out and see whether it's same with what u r saying and what i'm asking..

    Thanks

    Julia


  • Arthur Knight

    It is...please review my response.

  • Dens

    I see..

    Thanks so much..

    Regards,

    Julia


  • mokeefe

    Data in the SQL server and the data displayed in the grid are match.

    There's no problem in this.

    To reproduce the error, plz follow the steps.

    1. Run the sample that contains the grid with bound with 'Employees' table.

    2. Place the cursor on the new row.( last row of the grid to add new row <marked with asterik>)

    3. Then sort on the 'EmployeeID' column of the grid.

    Observe: EmployeeID column is changing the values each time we sort the EmployeeID column.< Check the data in the 'EmployeeID' column of new row of the grid >

    Thanks and Regards,

    Julia


  • Shelly

    Thanks for your answer Adam.

    So every time we sort on the grid, then it thinks that we're asking to create new record in the grid.

    Thanks for your workaround for this.

    Regards,

    Julia


  • Tycotrix

    Could not reproduce. Tested against SQL Server Employees table and Microsoft Access Employees table. Perhaps you have some events added that are modifying values. Try creating a new blank project and bind the Employees table and see if the problem persists.

  • dom_tiger_99

    It's still reproducible at my end.

    I've captured an avi file for this.

    But I can't post attached file in the forum :(

    Regards,

    Julia


  • Howard Yu

    No...everytime you display a primary key autonumbered (or any autonumbered field for that matter) in a grid and then sort, it thinks you want to create a new "virtual memory" record. (If you have insert enabled on the grid, it will post back to the table, otherwise it will only autonumber in active memory)

    The workaround, and the standard practice, is...if you want to display an identity field of some sort, create a new field in your table that is populated behind the scenes and doesn't autopopulate but is populated either through code or store procedures. Display this new field for sorting.

    Hope this makes sense,

    Adamus



  • Rob Cannon

    Julia,

    Primary key autonumber is set on the SQL end. The sort on the grid is done through autopostback and SELECT. The employeeid will change to match the record in the sort when you click the hyperlink for the column.

    Are you experiencing an unmatched employeeid with the associated names when you sort

    When you compare the SQL Server record with the grid view record, do they match or differ

    Adamus



  • loosie

    Julia,

    This is not an error. This is what it's supposed to do. This is sorting by the column of your choice.

    It sorts by desired column and matches the records.

    If you don't want the employeeid to change during sorting, don't sort.

    Adamus



  • Problem with AutoNumber key column