locked
SQL Update Statement Error RRS feed

  • Question

  • User535084190 posted

    hi everyone;

    I getting annoying with update statement

    con.Open();
                 Label authorname = e.Item.FindControl("LblAuthorHandler") as Label;
                
                 //When I Update 1 Column in Record Run perfectly
                     string cmdStrUpdatepoint = "UPDATE Registration SET uPoints +=1  WHERE UserName ='" + authorname.Text +"'";
                  // OR
                   string cmdStrUpdatepoint = "UPDATE Registration SET TimeRecievePoint ='"+DateTime.Now +"' WHERE UserName ='" + authorname.Text +"'";
                  
                   //When I Combine Like this "I Got SYNTAX ERROR" //Incorrect syntax near the keyword 'SET'. 
    string cmdStrUpdatepoint = "UPDATE Registration SET uPoints +=1, SET TimeRecievePoint ='"+DateTime.Now +"' WHERE UserName ='" + authorname.Text +"'";
    SqlCommand cmdUpdatepoint = new SqlCommand(cmdStrUpdatepoint, con); cmdUpdatepoint.ExecuteNonQuery(); Label3.Text = "werw :"+ Session["uNew"].ToString() ; con.Close();


    thanks

    Friday, April 19, 2013 8:58 AM

Answers

  • User-1360095595 posted

    You only use the SET keyword once. Spate the columns you're updating with a comma only. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 19, 2013 9:05 AM
  • User1083584480 posted

    Please use below one

    atepoint = "UPDATE Registration SET uPoints +=1, TimeRecievePoint ='"+DateTime.Now +"' WHERE UserName ='" + authorname.Text +"'"; 
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 19, 2013 9:06 AM

All replies

  • User1454061805 posted

    Please put what you are getting error.

    Friday, April 19, 2013 9:01 AM
  • User-1360095595 posted

    You only use the SET keyword once. Spate the columns you're updating with a comma only. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 19, 2013 9:05 AM
  • User535084190 posted
    con.Open();
                 
    Label authorname = e.Item.FindControl("LblAuthorHandler") as Label;
               
               
     //When I Update 1 Column in Record Run perfectly
                     
    string cmdStrUpdatepoint = "UPDATE Registration SET uPoints +=1  WHERE UserName ='" + authorname.Text +"'";
                 
    // OR
                   
    string cmdStrUpdatepoint = "UPDATE Registration SET TimeRecievePoint ='"+DateTime.Now +"' WHERE UserName ='" + authorname.Text +"'";
                 
                 
     //When I Combine "I Got SYNTAX ERROR"
    //Incorrect syntax near the keyword 'SET'.

     
    string cmdStrUpdatepoint = "UPDATE Registration SET uPoints +=1, SET TimeRecievePoint ='"+DateTime.Now +"' WHERE UserName ='" + authorname.Text +"'";
                   
    SqlCommand cmdUpdatepoint = new SqlCommand(cmdStrUpdatepoint, con);
                   cmdUpdatepoint
    .ExecuteNonQuery();
                   
      con.Close();

    Friday, April 19, 2013 9:06 AM
  • User1083584480 posted

    Please use below one

    atepoint = "UPDATE Registration SET uPoints +=1, TimeRecievePoint ='"+DateTime.Now +"' WHERE UserName ='" + authorname.Text +"'"; 
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 19, 2013 9:06 AM
  • User535084190 posted

    @ MetalAsp.Net

    thanks you sir run perfectly now, God Bless to all

    Friday, April 19, 2013 9:11 AM