SET MULTILOCKS ON SET DELETED ON CLOSE DATABASES ALL CLEAR oCA=CREATEOBJECT("CACategoriesODBC") * Use ODBC connection to the Northwind database on the local SQL Server as a data source oCA.DataSource=SQLSTRINGCONNECT("DRIVER=SQL Server;SERVER=(local);Trusted_Connection=Yes; DataBase=Northwind") IF !oCA.AutoOpen() AERROR(errs) DISPLAY MEMORY like errs return ENDIF SELECT (oCA.Alias) LIST ? "Add new category" INSERT INTO (oCA.Alias) (Name) VALUES ("New category") ?[TABLEUPDATE(.F.)=],TABLEUPDATE(.F.) LIST * delete the new record from the table GO bottom DELETE TABLEUPDATE(.F.) SQLDISCONNECT(oCA.DataSource) RETURN DEFINE CLASS CACategoriesODBC AS CursorAdapter Alias="CACategories" DataSourceType="ODBC" SelectCmd="select * from categories" CursorSchema="Id I, Name C(15), Descr M, Pict M" * set update properties Tables="Categories" KeyFieldList="Id" UpdatableFieldList="Name, Descr, Pict" UpdateNameList="Id Categories.CategoryId, Name Categories.CategoryName,"+; "Descr Categories.Description, Pict Categories.Picture" CompareMemo=.F. * Use ConversionFunc property to remove leading and trailing spaces from the Name field before sending * its value to the server ConversionFunc="Name AllTrim" * set conflict check type ConflictCheckType=3 FUNCTION AutoOpen() NODEFAULT RETURN this.CursorFill(.T.) && use schema ENDFUNC PROCEDURE AfterInsert LPARAMETERS cFldState, lForce, cInsertCmd, lResult IF lResult=.T. && get new Id LOCAL currentArea currentArea=SELECT() * if insert is successful, update ID field with * real value using @@IDENTITY variable from the server * (CategoryId is IDENTITY field) TRY IF 1=SQLEXEC(this.DataSource,"SELECT @@IDENTITY as CategoryId","IDRes") replace id with IDRes.CategoryId IN (This.Alias) USE IN IDRes ELSE AERROR(errs) DISPLAY MEMORY like errs ENDIF FINALLY SELECT (currentArea) ENDTRY ENDIF ENDPROC ENDDEFINEThanks,