Skip to content

ASP.net i have created web page using oracle db con, in that

Rajesh B

Asked Jul 31, 2013, 5:54 AM EDT4 answers
Share
LinkedInX
ASP.net i have created web page using oracle db con, using a button click am fetching some data's to textbox, then after that using a drop down onselectedindexchanged event aam clearing some of the textbox values, now i have to insert the data there in the window with out clearing in the textboxes and new texts in the textboxes whixh is cleared using ddl onselect event.

aspx page:

 
   
     
               
       
     
        OnSelectedIndexChanged="ddlcons" AutoPostBack="true">
   
   
   

     

   
           

   
           
           
               
       
               
               
       
               
               
                   
               
           
           
               
   
               
               
       
                        style="height: 26px" />
       
               
               
                   
       
               
           
           
               
                     
               
                     
               
                     
           
           
       

code behind file:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.OracleClient;


public partial class ora_con : System.Web.UI.Page
{


    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnora_Click(object sender, EventArgs e)
    {


        try
        {


            //use your own userid,password and datasorce
            string Constring;
            Constring = WebConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
            OracleConnection con = new OracleConnection(Constring);
            con.Open();
            OracleCommand cmd = con.CreateCommand();
            cmd.CommandText = "CREATE TABLE con(id varchar2(20),name varchar2(50))"; // uid not null
            cmd.ExecuteNonQuery();
            Response.Write("");
        }


        catch (Exception)
        {
            Response.Write("");
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        {
            string Constring, query;
            Constring = WebConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
            OracleConnection con = new OracleConnection(Constring);
            con.Open();
            query = "SELECT name,id FROM con where id = '" + TextBox3.Text.Trim() + "'";
            OracleCommand command = new OracleCommand(query, con);
            OracleDataReader reader = command.ExecuteReader();
            reader.Read();
            TextBox2.Text = reader[0].ToString();
            TextBox1.Text = reader[1].ToString();
            reader.Close();
            con.Close();
        }
    }






    protected void ddlcons(object sender, EventArgs e)
    {
        if (ddlcon.SelectedValue.ToString() == "1")
        {

            TextBox2.Text = "";
          //  TextBox3.Text = "";
        }
        else
        {
            Console.WriteLine("No Changes");
        }


    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        {
               string Constring;
            Constring = WebConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
            OracleConnection con = new OracleConnection(Constring);
            con.Open();
            string str = "insert into con  (name) values ('" + TextBox2.Text + "')";// here without clearing id will appear that id also should be insert with this name.
            OracleCommand cmd = new OracleCommand(str, con);
            cmd.ExecuteNonQuery();

            Response.Write("Inserted");



        }
    }
}

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You need to check for IsPostBack condition in the page_load event and you need to store the existing textbox values into viewstate. After the postback, read the values from postback and assign back to the controls.

    Please let me know, do you need sample for this?
    0
  • 0
    pls provide a sample code if you can
    0
  • 0
    Hi murali thank you, i have enabled all the textboxes in viewstate, but table containings some date value those things are not updating, wht to do for that?
    0