aspx page:
OnSelectedIndexChanged="ddlcons" AutoPostBack="true">
style="height: 26px" /> | ||
code behind file:
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 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajesh BPosted Jul 31, 2013, 11:09 AM
Rajesh BPosted Jul 31, 2013, 11:07 AM
Posted Jul 31, 2013, 10:11 AM
If you're allowed to AJAX then you can use UpdatePanel. You can place the dropdownlist control inside the updatepanel so that It will not do postback.
Posted Jul 31, 2013, 10:03 AM
Please let me know, do you need sample for this?