Oracle UPDATE from ASP.NET FORM

Hey experts,

I would like to know if anyone can provide me with an example of an Oracle INSERT function using C# and ASP.NET forms.  I would appreciate any help.

Thanks guys
Dan
DanHopperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndytwCommented:
an example method to insert into a table:

public void insertMessage(int sender, int recipient, DateTime date,
              string subject, string text)
{
  OracleCommand cmd = null;
  int recordsAffected;
 
  try
  {
    oraConnection = new OracleConnection(connString);
    oraConnection.Open();
 
    OracleTransaction insertTx = oraConnection.BeginTransaction();
    cmd = oraConnection.CreateCommand();
    cmd.Connection = oraConnection;
 
    StringBuilder commandText = new StringBuilder();
    commandText.Append("INSERT INTO messages ");
    commandText.Append("   (id, ");
    commandText.Append("    recipient, ");
    commandText.Append("    sender, ");
    commandText.Append("    text) ");
    commandText.Append("VALUES ");
    commandText.Append("   (messages_seq.NEXTVAL, ");
    commandText.Append("    :recipient, ");
    commandText.Append("    :sender,
      commandText.Append("    :text)");
    cmd.CommandText = commandText.ToString();
 
    cmd.BindByName = true;
    OracleParameter opSender = new OracleParameter("sender", OracleDbType.Int32);
    opSender.Direction = ParameterDirection.Input;
    opSender.Value = sender;
 
    OracleParameter opRecipient = new OracleParameter("recipient", OracleDbType.Varchar2);
    opRecipient.Direction = ParameterDirection.Input;
    opRecipient.Value = recipient;
 
    OracleParameter opText = new OracleParameter("text", OracleDbType.Clob);
    opText.Direction = ParameterDirection.Input;
    opText.Value = text;
 
    cmd.Parameters.Add(opSender);
    cmd.Parameters.Add(opRecipient);
    cmd.Parameters.Add(opText);
 
    recordsAffected = cmd.ExecuteNonQuery();
    insertTx.Commit();
  }
  finally
  {
    cmd.Dispose();
    closeConnection();
  }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DanHopperAuthor Commented:
Thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.