Asp tutorial. net oracle insert and update closed code
I thought I could start with the update method of the database tutorial, so I tried the following.
In oracle, the insert statement can use returning to return new records.
So our insert statement is like this.
Insert into tablename (uniquecolumn, othercolumns)
Values (table_seq.nextval, values) returning uniquecolumn into: unique_id.
After this operation, I can use the out parameter unique_id to obtain the primary key of the newly added record.
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.exe cutenonquery (SQL, parms. toarray ());
Pm. effectuniqueids. add (pr. value );
Return pm. effectuniqueids [0];
}
Else
{
Throw new exception ("Check the passed editparams. The Update column data cannot be blank! ");
}
Return null;
}
Other types of references used in it will be shared later.
The update statement can be as follows: select uniquecolumn from tablename where condition for update.
Select the row to be updated and add the update lock. Ensure that update is executed in order without confusion