ASP tutorial. NET Oracle Insert and update close code
I think I can start with the Update method of the database tutorial, so I have the following attempts.
Insert statements in Oracle can use returning to return new records.
So that's what our INSERT statement is.
INSERT INTO TableName (uniquecolumn,othercolumns)
VALUES (table_seq.nextval,values) returning Uniquecolumn into:unique_id.
After that, I can get the primary key for the new record through the Out parameter unique_id.
Public override Object Insert (editorparams pm)
{
if (PM!= null && pm.editvalues.count > 0)
{
querysetting qs = Configenginer.instance.datamodels[pm.modeltype] ;
String Insertformart = @ "INSERT INTO #oysterval: tablename# (#oysterval: uniquecolumn#, #oysterval: columns#)
VALUES (# Oysterval:tablename#_seq.nextval, #oysterval: values#) Returning #oysterval: uniquecolumn# into:unique_id ";
dictionary<string, string> vals = new dictionary<string, string> ();
list<idataparameter> parms = new list<idataparameter> ();
Vals.add ("tablename", qs.tablename);
Vals.add ("Uniquecolumn", qs.uniquecolumn.columnname);
Vals.add ("Columns", pm.insertcolumns);
Vals.add ("Values", pm.insertvalues);
System.Nullable
var unqtype = Qs.uniquecolumn.propertytype;
if (Unqtype.fullname.contains ("System.Nullable"))
{
var types = unqtype.getgenericarguments ();
if (types!= null && types.length > 0)
{
Unqtype = Types[0];
}
}
var PR = new OracleParameter (": unique_id", Activator.CreateInstance (Unqtype));
Pr.direction = Parameterdirection.inputoutput;
Parms.add (PR);
Parms.addrange (pm.dataparms);
String sql = Insertformart.tooystertemplate (vals);
Pm.effectcount = dbenginer.instance.executenonquery (sql, Parms.toarray ());
Pm.effectuniqueids.add (Pr.value);
return pm.effectuniqueids[0];
}
Else
{
Throw new Exception ("Please check incoming editparams, update column data cannot be empty!");
}
return null;
}
Other types of references used in the inside, will be slowly shared later.
Update can do this: select Uniquecolumn from tablename where condition for update.
Select the row that will be updated and add the lock for update. Make sure update executes in order without confusion