Oracle dynamically adds a record, and oracle dynamically adds a record
/// <Summary>
/// Add an object
/// </Summary>
/// <Typeparam name = "T"> entity name </typeparam>
/// <Param name = "dic"> fields to be added </param>
/// <Returns> returns the number of affected rows </returns>
Public static int AddEntity <T> (Dictionary <string, object> dic) where T: class, new ()
{
T t = new T ();
Var propertys = typeof (T). GetProperties ();
String FieldKey = string. Empty;
String FieldValue = string. Empty;
Foreach (var p in propertys)
{
Foreach (var key in dic. Keys)
{
If (p. Name. ToUpper () = key. ToUpper ())
{
FieldKey + = p. Name. ToUpper () + ",";
If (p. PropertyType = typeof (int ))
{
Try
{
If (string. IsNullOrEmpty (dic [key]. ToString ()))
{
FieldValue + = Convert. ToInt32 (dic [key]) + ",";
}
Else
{
FieldValue + = Convert. ToInt32 (dic [key]) + ",";
}
}
Catch (Exception ex)
{
HttpContext. Current. Response. Write ("prompt:" + ex. Message );
}
}
Else if (p. PropertyType = typeof (DateTime ))
{
// If the time is null, the current time is assigned a value.
If (string. IsNullOrEmpty (dic [key]. ToString ()))
{
FieldValue + = "to_date ('" + Convert. toDateTime (System. dateTime. now. toString ("yyyy-MM-dd HH: mm: ss") + "', 'yyyy-mm-dd HH24: mi: ss '),";
}
Else
{
FieldValue + = "to_date ('" + Convert. toDateTime (dic [key]. toString () + "', 'yyyy-mm-dd HH24: mi: ss '),";
}
}
Else
{
FieldValue + = "'" + dic [key]. ToString () + "',";
}
}
}
}
String tableName = GetTableNameToModel (t );
String SQL = "insert into" + tableName + "(" + FieldKey. trimEnd (','). toString () + ") values (" + FieldValue. trimEnd (','). toString () + ")";
Int result = OracleHelper. ExecuteNonQuery (SQL );
Return result;
}