Auto increment values always negative in Gridview
trying to make a sample Master-Detail relation ship database example in vb.net
When I add MasterTable a new row via bindingnavigator and save via savebutton autoincrement field goes -1 -2... negative values hence cannot get correct ID numbes saved in table rows till I close open sample application.
So This is a big problem for me.How can I see correct autoincrement ID numbers in gridview after savebutton ?.Just ID numbers saved to mdb.but cannot see them i gridview and displaying negative weird numbers.
This problem is important because without getting ID numbers cannot bind Detail table rows to newly recorded master table rows.
This driving me crazy since last 2 years.
do you have a real solution for this or a small exaple ?
(thanks before for any answers)
Re: Auto increment values always negative in Gridview
Basically, you can't do what you want with Access. If you use a proper database, like SQL Server Express, then what you want to do is a simple case of adding a little bit of SQL code and setting a couple of properties.
Re: Auto increment values always negative in Gridview
I am sure this problem drives people crazy so much and I am not the one.
Its same as in SQL Server Express always new records IDs (identity) -1 -2 if you press (bindingnavigator's) savebutton or not.cannot see real IDs without open close Application exe.This is SQLServer 2008 Express on XPSP2x64.
How can you tell step by step to make me detect what I am doing wrong ?
He is an old senior developer and can understand immediately.
better anybody can send a simple sample zipped primitive project example attached somewhere ?
This is not todays problem.I am looking it for last 2 years.and really couldnt find any good answer. with lost 10s of hours and still nothing.
or can some friend refer a link that includes an Winforms example that exactly saves master-detail datas as expected ? in access or SQLServer no matter.
everything is amaizng in asp.net but I still cannot sure about winforms and data operations.So cannot understand how a gridview cannot get autoincrement value ?
This cannotbe done by database experts? Should I have to write storedproceduers and some of codes manually ? Really dont know where I am wrong.
in conclusion Adding rows to master table doesnt get corect IDs andalso detail Rows have been lost everytime because their connected masterID is unknown.so DetiailTable.ParentID is alwys being -1.and losing their master row.How can you tell this problem fix ?
if I failure I unfortunatelly have totell my 100s of students "dont use dotnet winforms for database.So lesson finishes here."
thank you
Re: Auto increment values always negative in Gridview
No it's not the same in SQL Server. With SQL Server it's very simple. In fact, if you use the data tools built into the IDE, it will all be done for you.
The difference is that the SQL Server ADO.NET provider supports multiple statements per command, while the Jet and ACE OLE DB providers for Access don't. What that allows you to do is add a SELECT statement to the end of your INSERT, which can refresh your data with any values generated by the database. For example, you might do this:
sql Code:
INSERT INTO Parent (Column1, Column2) VALUES (@Column1, @Column2); SELECT ID = SCOPE_IDENTITY()
SCOPE_IDENTITY returns the last ID generated within the current scope, and that query assigns it to the ID column of the row that was just inserted. Assuming that you have a DataRelation in your DataSet that will cascade updates, that's all you need.