Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
if (con.State.ToString() == "Open")
        {
            MySqlCommand cmd = new MySqlCommand("insert into discussion values(@g,@h,@i,@j)", con);
            
                cmd.Parameters.AddWithValue("@g",Session["user"]);
                cmd.Parameters.AddWithValue("@h", TextBox3.Text);
                cmd.Parameters.AddWithValue("@i", TextBox1.Text);
                cmd.Parameters.AddWithValue("@j", TextBox2.Text);
                MySqlCommand cmdd = new MySqlCommand("UPDATE users SET points=@k WHERE user_name=@userName", con);
                cmd.Parameters.AddWithValue("@k", HiddenField1.Value);
                cmd.Parameters.AddWithValue("@userName", Session["user"].ToString());
                cmd.ExecuteNonQuery();
                Response.Redirect("~\\show.aspx");

i want to increase the points value every time user he click the button above code is not working please help me
Posted

1 solution

The problem is you are using wrong MySqlCommand object when setting parameters for cmdd.
These two lines
C#
cmd.Parameters.AddWithValue("@k", HiddenField1.Value);
cmd.Parameters.AddWithValue("@userName", Session["user"].ToString());


should be corrected as
C#
cmdd.Parameters.AddWithValue("@k", HiddenField1.Value);
cmdd.Parameters.AddWithValue("@userName", Session["user"].ToString());


Also you have forgotten this line too
C#
cmdd.ExecuteNonQuery();


Hope this will help to you :-)
 
Share this answer
 
Comments
ben.josey 17-Aug-14 7:37am    
dude i tried your code but it not helped me
[no name] 17-Aug-14 8:26am    
Whoa "dude" try not to load us down with so much useful information. "Not working" and "not helped" convey so much information to us that it just boggles the mind. Rewrite your code so that it makes sense and you would see the problem for yourself.
Dilan Shaminda 17-Aug-14 8:40am    
is there any exception you are getting?
ben.josey 17-Aug-14 8:47am    
dude no exception no errors but the values are not updating in db.
Dilan Shaminda 17-Aug-14 8:49am    
then debug your code and check the value you are passing to @k parameter

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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