When Using ADO.net typed datasets, Visual Studio Automatically creates the Update, and Insert Methods, however the return integer value indicate if the record was added successfully or not, in order to get the ID of the newely created entry one can access the ID field of the original dataset that was used to add contents to the database.
In order to make this happen one needs to enable “Refresh the data table” in Advanced Options
once done, on update the source datatable contents will be updated with the inserted Id of the new record.
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
public int AddModule(dsDomainModules.tblDomainModulesRow Module)
{
int nResult = 0;
try
{
dsDomainModules.tblDomainModulesDataTable objModule = new dsDomainModules.tblDomainModulesDataTable(); objModule.AddtblDomainModulesRow(Module); if (_dsDomainModulesTableAdapter.Update(objModule) == 1) //update was successful nResult = Module.nModuleId;
}
catch (Exception ex)
{
//do something with exception
}
return nResult; }
Filed under: Uncategorized



