Need on the best way to going about programming this in c#. I'm trying to do an if record exists update statement else insert statement, Updated code but still have issues with insert/updating into database. Nothing shows in database after execution from this code:
String updCmdTxt = "UPDATE..";
String insertCmdTxt = "INSERT ..";
using (var scope = new TransactionScope())
{
using (var con = new OracleConnection(strConnection))
{
bool isDuplicate = false;
var insertcmd = new OracleCommand(insertCmdTxt, con);
try
{
con.Open();
......add params
insertcmd.ExecuteNonQuery();
con.Close();
Response.Redirect("test.aspx?Id=" + labelRID.Text);
}
catch (OracleException x)
{
isDuplicate = true; //determine if the exception is about duplicates.
if (!isDuplicate)
{
throw;
}
}
finally
{
insertcmd?.Dispose();
}
if (isDuplicate)
{
using (var updcmd = new OracleCommand(updCmdTxt, con))
{
....
updcmd.ExecuteNonQuery();
}
}
scope.Complete();
Response.Redirect("test.aspx?Id=" + labelRID.Text);
}
}
}
Is there a better way to program this and if so how?