Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
U CAN JOIN ME ON TEAM VIEWER
ID 175 735 453
PWD - 7977
 
error is there in update query
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 22-Mar-13 22:42pm
Edited 22-Mar-13 23:15pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Look at your update query:
"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.
  Permalink  
Comments
Amirsalgar1 at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
 
Change your update statement as shown below
OleDbCommand cmd = new OleDbCommand("UPDATE LOGIN SET CPoints " + tt + " WHERE U_name = '" + txtusername.Text + "'" , con);
 
Regards,
  Permalink  
Comments
Amirsalgar1 at 23-Mar-13 4:22am
   
thanks sir for reply .. ok i'm changing
Prasad Khandekar at 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 at 23-Mar-13 4:27am
   
the name tt is does not exist in current context
Amirsalgar1 at 23-Mar-13 4:33am
   
u there?
Amirsalgar1 at 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)

  Print Answers RSS
0 OriginalGriff 200
1 PIEBALDconsult 150
2 BillWoodruff 148
3 Jochen Arndt 135
4 DamithSL 130
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 23 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100