ASP.NET C# - Updating Oracle database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sumalatha055
    New Member
    • Aug 2008
    • 3

    ASP.NET C# - Updating Oracle database

    i had written this to update data in table but its not responding
    can u please help ma?
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;
    using System.Data.OracleClient;
    public partial class _Default : System.Web.UI.Page
    {
        OracleConnection objcon= new OracleConnection("Data Source=fsoft;user=fcctest;password=fcctest");
        OracleCommand objcmd = new OracleCommand();
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            objcon.Open();
            OracleDataAdapter objda = new OracleDataAdapter(" select *  from CAN_PERSONALINFO where REFERANCE_ID=" + TextBox1.Text + " ", objcon);
            DataSet objds = new DataSet();
            OracleDataAdapter objda1 = new OracleDataAdapter(objcmd);
            objda.Fill(objds);
            GridView1.DataSource = objds.Tables[0];
            GridView1.DataBind();
            objcon.Close();
    
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                OracleDataAdapter objcmd1 = new OracleDataAdapter("update  CAN_PERSONALINFO  SET FIRST_NAME=" + TextBox2.Text + " where REFERANCE_ID =" + TextBox1.Text + " ", objcon);
                objcon.Open();
                OracleDataAdapter objcmd2 = new OracleDataAdapter("select * from CAN_PERSONALINFO where REFERANCE_ID=" + TextBox1.Text + " ", objcon);
                objcmd.ExecuteNonQuery();
                DataSet ds2 = new DataSet();
                OracleDataAdapter objda2 = new OracleDataAdapter(objcmd2);
                objda2.Fill(ds2);
                GridView1.DataSource = ds2.Tables[0];
                GridView1.DataBind();
                objcon.Close();
                Label1.Text = "update your FIRST_NAME";
    
            }
    
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
    Last edited by DrBunchman; Aug 20 '08, 01:57 PM. Reason: Added [Code] Tags - Please use the '#' button
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi sumalatha055,

    Welcome to Bytes.com! I hope you find the site useful but I need to mention a couple of things:

    You've posted your question in the ASP Forum which is for Classic ASP only - I've moved it for you but in future please post all ASP.NET questions in the .NET Forum.

    Please don't forget to wrap your code in CODE tags - it makes your posts much easier to read.

    Your question does not contain enough detail - what do you mean by not responding? Are you getting an error?

    Please read the Posting Guidelines if you have not done so already.

    Good luck finding a solution,

    Dr B

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      You have several problems. You keep declaring new DataAdapters, but you are using (and trying to use) the first one. You need a better understanding of what's going on.

      What I usually do is declare a connection, command, and adapter as global. Then I initialize them in my constructor/page_load method. But keep using the same one.

      Also, you don't need to open and close your connections when you use a DataAdapter. It does that for you.

      EDIT:
      Spotted another problem.

      You delcare a DataAdapter with an update command, which is already a problem, because you can't do that. You have to declare them with a select statement. But then you never use it.

      You need to seriously rework your logic. Read this article I wrote. Hopefully you will have a better understanding about using DataAdapters and commands.

      Comment

      • kank999
        New Member
        • Dec 2012
        • 2

        #4
        Dear sumalatha055

        You have not used refrence file of Oracle provider.
        You must use :

        Using Oracle.DataAcce ss;
        This will support for OracleDataAdapt er and oracle connection.

        Regards

        Comment

        Working...