Board index » delphi » Unable to insert to MS-SqlServer table with IDENTITY field
finel...@singnet.com.sg (Simon Ee)
![]() Delphi Developer |
Sat, 26 Sep 1998 03:00:00 GMT
|
finel...@singnet.com.sg (Simon Ee)
![]() Delphi Developer |
Sat, 26 Sep 1998 03:00:00 GMT
Unable to insert to MS-SqlServer table with IDENTITY field
Hi guys, I'm sorry if this question has been asked before, but I'd
really appreciate it if someone could help me out here. My Delphi form fails to insert new records into my database table!!! We're running MS SQLServer 6.0 thru ODBC, and the table in question Evidently Delphi expects a value for the primary key (of course!) but Many, many thanks in advance for all replies, Simon. BTW -- The error message I get goes like this: Project IV_MTRAN.EXE raised exception class EDatabaseError with |
Jasen M. Fic
![]() Delphi Developer |
Sat, 26 Sep 1998 03:00:00 GMT
Re:Unable to insert to MS-SqlServer table with IDENTITY fieldQuoteSimon Ee wrote: Had this same problem the first time I used identity properties. What you should do is this: At some point after the table has been activated, set the primary key tblCustomer.FieldByName('ID').Required := False; That should do it. -- |
Troy Sorza
![]() Delphi Developer |
Sat, 26 Sep 1998 03:00:00 GMT
Re:Unable to insert to MS-SqlServer table with IDENTITY fieldQuotefinel...@singnet.com.sg (Simon Ee) wrote: suffering. The BDE does not like idenity or autoinc fields. I know this sounds like a pain in the butt. But it will work for all SQL backends so if you ever migrate to ORACLE or another server you wont have to rewrite your delphi app. IDENTITY is unique to MS SQL. Once you get it set up you only need to call a storeprocedure to get a unique number. The other problem with IDENITY is that you don't know what it is untill you post it. We had a problem of how to create child records if we did not know the IDENTIY yet? The MS SQL stupid solution was to post the customer then select the customer so we would know the IDENTITY then use that number for the customers. We spent weeks trying to get around the problem by using Table1.IdentiyField.Required = False; This worked fine for simple applications. However in complex This is the solution that I found on the net on on compuserve. Use a table called SYSID to store the autoincrementing numbers SYSID TABLE_NAME NEXT_ID Then have a stored procedure that you pass the TABLE_NAME and it will Then in all your tables "customers", "inovice" change the identiy When your app goes to create a new customer. The first thing you do This is the readme I got with the Identiy VCL that scott wrote. I did I'll email you scotts zip file. --------------------------------------------------------------------------- [THE PROBLEM] For some reason however, the BDE used by Delphi, refuses to It appears that the BDE wants to be "responsible" for all primary key [THE SOLUTION] * Step #1 * Step #2 * Step #3 That's when I got the idea of creating a trigger for each auto-id A generic script for this trigger is provided in GENID.TRI. Before * Step #4 [SUMMARY] If you have any questions or comments, please email me at 74403,1376. W. Scott Morgan |
Mark Pattis
![]() Delphi Developer |
Sun, 27 Sep 1998 03:00:00 GMT
Re:Unable to insert to MS-SqlServer table with IDENTITY fieldGoodness me, that just what i'm doing. ODBC is so god dam slow though, anyway I am currently trying to wrap my form edits/posts around a transaction. I think this is the only way to go? I've managed to stop Delphi complaining by explicity posting and refreshing (close/open) the query. But in my case everything is tied together relationally and I don't If anyone has an alternative to using transactions, please let me Mark. Quotefinel...@singnet.com.sg (Simon Ee) wrote: |
Simon
![]() Delphi Developer |
Fri, 09 Oct 1998 03:00:00 GMT
Re:Unable to insert to MS-SqlServer table with IDENTITY fieldThanks, Troy and everybody for your suggestions. Now I've finally managed to get everything working just like it was supposed to. ;-) Simon Ee. Quotetroy.sorz...@adic.ipu.com (Troy Sorzano) wrote: |
1. MS SQL Server Insert a record with a IDENTITY field
2. Insert to MS SQLServer table
3. Paradox autoinc fields vs MS SQL identity fields
4. Insert and Identities/MS SQL
5. Unable to create tables from delphi with ADO, and SQLServer 7
6. Insert record w/SQL Server identity field
7. Get value of Identity field on insert on sql7
8. How to change field value of inserted record in insert trigger for MS SQL
9. MSSQL 6.0, Identity field, insert
10. DELPHI ClientDataset Insert into MSSQL Table with IDENTITY Column Problem / Question