Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
U CAN JOIN ME ON TEAM VIEWER
ID 175 735 453
PWD - 7977

error is there in update query
C#
public partial class _Default : System.Web.UI.Page 
{
    OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
    
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }

    protected void btnsubmitvoucher_Click(object sender, EventArgs e)
    {
        int strvoucher = Convert.ToInt32(txtvoucher.Text);
    
        con.Open();
        OleDbDataAdapter da = new OleDbDataAdapter("select * from coupen where voucher=" + strvoucher, con);
        DataTable dt = new DataTable();
        da.Fill(dt);
        con.Close();
        if (dt.Rows.Count > 0)
        {
            int V = Convert.ToInt32(dt.Rows[0][0]);        

            if (strvoucher == V )
            {
                OleDbCommand cmdselect = new OleDbCommand("select* from coupen where voucher=" + strvoucher, con);
                OleDbDataReader rs;            
                con.Open();
                
                rs = cmdselect.ExecuteReader();
                if (rs.Read()) 
                {
                    txtCpoints.Text = rs.GetValue(2).ToString() ;

                    int tt = Convert.ToInt32(txtCpoints.Text);//txtusername.Text = rs.GetValue(2);
                }
                OleDbCommand cmd = new OleDbCommand("UPDATE LOGIN set CPoints= tt where U_name = '"+txtusername.Text+"' " , con);
                cmd.ExecuteNonQuery();
                
                // OleDbCommand cmddelete = new OleDbCommand("delete from coupen where voucher=" + strvoucher, con);
                // cmd.ExecuteNonQuery();
                con.Close();
                lblmsg.Text="Congrats your voucher is accepted check your points !!!";
            }
            else
            {
                lblmsg.Text = "Invalid voucher ..!!";
            }
        }
        else
        {
            lblmsg.Text = "Invalid Login..!!";
        }
    }
}
Posted
Updated 22-Mar-13 22:15pm
v2

Look at your update query:
SQL
"UPDATE LOGIN set CPoints= tt where U_name = '"+txtusername.Text+"' "
The value you are trying to set it to is fixed: "tt" and SQL does not see that as a string (because it does not have quotes around it) so it is trying to find it as a variable or columns name. It cant. so it assumes it is a paramater value which you have not defined. Looking at your code, I suspect that you want the value in the variable tt rather than the variable name here.

But don't do it like that! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 
Comments
Amirsalgar1 23-Mar-13 4:43am    
thanks for reply sir..
right sir , thats why it is showing the error ... the name tt is does not exist in current context .. where should i make changes?
Amirsalgar1 23-Mar-13 5:16am    
sir i have made some changes it is not showing any error but .. value is not adding in login table in CPoints coloumn
Hello,

Change your update statement as shown below
C#
OleDbCommand cmd = new OleDbCommand("UPDATE LOGIN SET CPoints " + tt + " WHERE U_name = '" + txtusername.Text + "'" , con);


Regards,
 
Share this answer
 
Comments
Amirsalgar1 23-Mar-13 4:22am    
thanks sir for reply .. ok i'm changing
Prasad Khandekar 23-Mar-13 4:35am    
Please also thanks OriginalGriff. He has also provided explanation for why your earlier query was not working. Remembering it will help you write correct queries in future.
Amirsalgar1 23-Mar-13 4:27am    
the name tt is does not exist in current context
Amirsalgar1 23-Mar-13 4:33am    
u there?
Amirsalgar1 23-Mar-13 5:14am    
sir i have made some changes it is not showing any error but .. value is not adding in login table in CPoints coloumn

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