I have an aspx page in that I have a button.
Now what I want it, i want to write a query on the onclick of the button. How to to that. ?
Here is my code:-
<asp:Button ID="btnUpdate" runat="server" Text="Update Broker Rating"
Width="145px" onclick="btnUpdate_Click" />
Also see my C# code:-
protected void btnUpdate_Click(object sender, EventArgs e)
{
// how to write the query
}
UPDATE
I tried like below, but I am getting error as
connection property has not been initialized
Here is my code:-
protected void btnUpdate_Click(object sender, EventArgs e)
{
//string strConnString = "";
OracleConnection con = new OracleConnection(ConfigurationManager.AppSettings["OracleConn"]);
string strQuery = "SELECT ab.broker_id,CASE WHEN SYSDATE - la.creation_date <= 180 THEN 'A' WHEN SYSDATE - cef_dt <= 30 THEN 'B' ELSE 'C'END rating " +
"FROM xxacl_pn_new_cha_part ab,xxacl_pn_lease_det ld,xxacl_pn_leases_all la,xxcus.xxacl_pn_customer_enquiry_v ce " +
"WHERE ab.broker_id = ld.broker_id AND ld.booking_no = la.booking_no AND ab.broker_id = ce.broker_id";
OracleCommand cmd = new OracleCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
try
{
con.Open();
OracleDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
//update message to be displayed here
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}