c# - Creating a new row in empty datatable and get correct next OID -


i know seems simple doesn't seem work. have table in msaccess database empty did have records @ point, when datatable.newrow returns new row objectid field 0 (autoincerement field). after commit new row database has objectid 84 (or whaterver think next number should be) need have correct objectid value before commit because used in join table. if have @ least 1 record on datatable , datatable.newrow, objectid new row correct 84. here code i'm using datatable:

                string ssql = "select * <tablename>"                                    idbdataadapter dbadapter = getdataadapter(ssql);                 dbadapter.missingschemaaction = missingschemaaction.addwithkey;                 if (dbconnection.state == connectionstate.closed)                     dbconnection.open();                 try                 {                     dataadapterfill(dbadapter, dataset, stablename);                 }                 catch (oledbexception oledbex)                 {                     if (oledbex.message.contains("no value given 1 or more required parameters"))                         throw new exception(string.format("where clause {0} contains correct fields table {1}", swhereclause, stablename), oledbex);                     else                         throw oledbex;                 }                 catch                 {                     dbconnection.close();                     ((idisposable)dbadapter).dispose();                     throw;                 }                 dbadapter.tablemappings.add(stablename, stablename);                 datatable = dataset.tables[0]; 


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -