Click here to Skip to main content
15,923,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can anyone give code for this?

I have two tables FIR and PIF....and also i have Public and primary key....ok then ...the FIR table has one primarykey and also the PIF table has its primarykey....right.i have anotherone form called Audit..it has field like public key,primarykey and one submit button....when i enter the primary key for any table the desired primarykey if matches it should redirect to another page...i have done for one table..but how to do for both?

code is:
protected void selected_items(object source, DataListCommandEventArgs e)
   {

       if (con.State == ConnectionState.Closed)
       {
           con.Open();
       }
       if (e.CommandName == "Submit")
       {
           TextBox pri_key = (TextBox)e.Item.FindControl("txtprivate_key");
           if (pri_key.Text != " ")
           {
               txtprivate_key = Int32.Parse(pri_key.Text);
           }


           SqlCommand cmd = new SqlCommand("select public_key from audit where private_key='" + txtprivate_key + "' and t_name='fir'", con);
           pif();
           if (Convert.ToInt32(cmd.ExecuteScalar()) == 0)
           {
               Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('Private Key not Valid')</script>");

           }
           else
           {
               Response.Redirect("fir2.aspx");
           }
       }
   }
   public void pif()
  {
       if(con.State==ConnectionState.Closed)
       {
           con.Open();
       }
       SqlCommand cmd1 = new SqlCommand("select  public_key,t_name from audit where private_key='"+txtprivate_key+"' and t_name='pif'", con);
           if (Convert.ToInt32(cmd1.ExecuteScalar()) == 0)
           {
               Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('Private Key not Valid')</script>");

           }
           else
           {
               Response.Redirect("pif2.aspx");
           }
   }
Posted
Updated 23-Dec-11 17:14pm
v2
Comments
[no name] 23-Dec-11 23:15pm    
Format code snippets
[no name] 23-Dec-11 23:19pm    
What do you mean, how to do for both tables?

You never use direct unvalidated input to you SQL statements, ever. Period.
Read up on SQL injection attacks and parameters.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900