title: Unable to insert row into table using an Oracle Connection
body: <p>I would like to know what's the problem, or your advice to connect to Oracle. I'm trying with this but when I try to insert values, it doesn't work.</p>
  
  <p>I'm using the Visual Web Developer 2008 and when I add a database on Database Explorer connections, it's working. But when I try to connect via this connection string, it doesn't work. What am I missing?</p>
  
  <p>I don't get an exception, so apparently it's working well. But this code apparently doesn't insert! The <code>id</code> column is a <code>varchar(45)</code>. I created the table "test" just for testing purposes.</p>
  
  <pre><code>using System.Data;
  using System.Data.OracleClient;
  
  public partial class _Default : System.Web.UI.Page
  { 
      //string oradb = "Data Source=localhost;User ID=root;Password=jesua;Unicode=True;";
      String oracle = "User ID=root;Password=jesua;Unicode=True;Data Source=localhost;";
      OracleConnection con = new OracleConnection();
  
      public void Conectar() {
          try 
          {
              con.Close();
              con.ConnectionString = oracle;                 
              con.Open();
          }
          catch(Exception ex){
              throw new Exception("No Conecto " + ex);
          }  
      }
  
      public void desconectar() {
          // con.ConnectionString = oracle;
          con.Close();
      }
  
      public void agregar() {
          this.Conectar();
          OracleCommand query = new OracleCommand("INSERT INTO testing (id) VALUES ('testing')");
          query.ExecuteNonQuery();
          desconectar();           
      }
  
      protected void Button1_Click(object sender, EventArgs e)
      {
          try {
              agregar();
          }
          catch(Exception ex){
              Console.Write("No agrego " + ex);
          }
          TextBox1.Text = "Conected";
      }
  }
  </code></pre>
  
  <p>--------------------------UPDATE------------------</p>
  
  <p>So, </p>
  
  <p>i found the way to do that, </p>
  
  <p>i hope anyone here can use this code in a future... </p>
  
  <p>This code creates the connection betwen Oracle and asp.net C#</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using Oracle.DataAccess.Client; // ODP.NET Oracle managed provider
  using Oracle.DataAccess.Types;
  
  namespace proyecto
  {
  public partial class WebForm1 : System.Web.UI.Page
  {
      public void dbconnect() {
          string oradb = "Data Source=localhost;User ID={Yoir ID};Password={Your Password};";
  
          OracleConnection conn = new OracleConnection(oradb); // C#
          conn.Open();
          OracleCommand cmd = new OracleCommand();
          cmd.Connection = conn;
          cmd.CommandText = "INSERT INTO TESTING(id) VALUES ('valor')"; 
          int rowsUpdated = cmd.ExecuteNonQuery(); 
          if (rowsUpdated == 0) 
           Console.Write("Record not inserted"); 
          else 
          Console.Write("Success!"); 
          conn.Dispose(); 
      }
  
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
  
      protected void Button1_Click(object sender, EventArgs e)
      {
          this.dbconnect();
  
      }
     }
   }
  </code></pre>
  
  <p>Good Luck!</p>