Mega Code Archive

 
Categories / C# Tutorial / ADO Net
 

Do a delete command to Oracle database

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OracleClient;   public class MainClass   {     public static void Main()     {       OracleConnection oraConn = new OracleConnection();       string connString = "User Id=oranetuser; Password=demo; Data Source=oranet";       if (oraConn.State != ConnectionState.Open)       {         try         {           oraConn.ConnectionString = connString;           oraConn.Open();           MessageBox.Show(oraConn.ConnectionString, "Successful Connection");         }         catch (Exception ex)         {           MessageBox.Show(ex.Message,"Exception Caught");         }       }       if (oraConn.State == ConnectionState.Open)       {         string sqlDelete = "delete from PlayerTable where player_num = :p_num";         OracleCommand cmdDelete = new OracleCommand();         cmdDelete.CommandText = sqlDelete;         cmdDelete.Connection = oraConn;         OracleParameter pPlayerNum = new OracleParameter();         pPlayerNum.DbType = DbType.Decimal;         pPlayerNum.Value = 1;         pPlayerNum.ParameterName = "p_num";         cmdDelete.Parameters.Add(pPlayerNum);         cmdDelete.ExecuteNonQuery();         cmdDelete.Dispose();       }     }   }