Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to have a database column and name it as status.

When I click a link Eg:Activate in my page it should AUTOMATICALLY change the status as ACTIVATED in my DATABASE TABLE .

Please Help me to attain this.

What I have tried:

I have tried to place a link, but the problem is I am not able to Change the status as I mentioned above.
Please help.
Posted
Updated 4-Jul-17 21:35pm

1 solution

try

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Activate</asp:LinkButton>


protected void LinkButton1_Click(object sender, EventArgs e)
       {
           string constr = "Your connection string";
           using (SqlConnection con = new SqlConnection(constr))
           {
               string sql = "update YourTableName set Status = 'Activated'";
               using (SqlCommand cmd = new SqlCommand(sql))
               {
                   con.Open();
                   cmd.ExecuteNonQuery();
                   con.Close();
                   LinkButton1.Text = "Activated";
               }
           }
       }
 
Share this answer
 

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