Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
in my project..

XML
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Check Username availability Using Ajax</title>

</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="txtvoucher" runat="server"></asp:TextBox>
    <asp:Button ID="btnsubmitvoucher" runat="server"
        onclick="btnsubmitvoucher_Click" Text="Submit" />
&nbsp;&nbsp;&nbsp;&nbsp;
    <br />
    <br />
    <asp:Label ID="lblmsg" runat="server"></asp:Label>
    <asp:TextBox ID="txtCpoints" runat="server"></asp:TextBox>
    <asp:TextBox ID="txtusername" runat="server"></asp:TextBox>
    </form>
</body>
</html>

This my default page design.

and code behind
C#
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
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();

                    //txtusername.Text = rs.GetValue(2);

                    int tt = Convert.ToInt32(txtCpoints.Text);
                    OleDbCommand cmd = new OleDbCommand("UPDATE LOGIN SET CPoints " + tt + " WHERE U_name = " + txtusername.Text, con);
                }
                     //OleDbCommand cmddelete = new OleDbCommand("delete from coupen where voucher=" + strvoucher, con);
                     //cmddelete.ExecuteNonQuery();
                
                con.Close();
                lblmsg.Text = "Congrats your voucher is accepted check your points !!!";
            }
            else
            {
                lblmsg.Text = "Invalid voucher ..!!";
            }
        }
        else
        {
            lblmsg.Text = "Invalid Login..!!";
        }
    }
}

and the have used access database.

I have two tables:
1. coupen
2. LOGIN

In coupen table fields are:
voucher-Number,<br />
RS-Number,<br />
CPoints-Number,<br />
Datec-Date/Time

and the data in this table data
222,2,2,3/15/2013
111,4,4,3/18/2013


In LOGIN Table field are
U_id-AutoNumber,<br />
U_name-Text,<br />
U_Email-Memo,<br />
U_Mobile-Memo,<br />
U_password-Memo,<br />
CPoints-Number...


in this table data:
1,aaa,a@a.com,123456,123
3,bbb,ashish@gmail.com,987654,-...

when run the page plz Enter the voucher no in the text box..and click submit...after clicking button point will be displayed in 2nd text box , Enter the user name in 3rd text box...and again click submit button...

when clicked the button the "CPoints" related data will be deleted from coupen and that "CPoints" will be update in the LOGIN table related to the U_name..

problem is that when i clicked the submit button 2nd time the login table is not updated..

if u getting my point.
plz help me...
Posted
Updated 24-Mar-13 7:51am
v4
Comments
Raj@88 24-Mar-13 9:50am    
plz anybody help me...to solve this..
Prasad Khandekar 24-Mar-13 10:14am    
How about keeping a hidden field to track this. On first click (field value = 0) you just retrieve the cpoints and update the textbox. Increment the field value by one. On second click (field value = 1) fire the Update SQL followed by delete SQL. With whatever code you have posted above no updates or deletes are going to happen.
Raj@88 24-Mar-13 13:58pm    
Mr.Prasad Khandekar i hv commented the delete query...if u remove it,,,the program execute properly but not update command

1 solution

You set your parameters and objects first, then open, execute and close.
So on your update, you opened, did nothing, and closed it.

You may want to consider using parameters in the future

Dim objConn As New SqlConnection(strConnString)
Dim strSQL As String = "UPDATE Perm SET Res=@Res WHERE LoginID=@LoginID"         
Dim objCmd As New SqlCommand(strSQL, objConn)

Dim paramLoginID As SqlParameter
paramLoginID = New SqlParameter("@LoginID", SqlDbType.VarChar, 80)
paramLoginID.Value = m_Login
objCmd.Parameters.Add(paramLoginID)

objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()


I see this which doesn't look correct, might want to clean it up
OleDbCommand cmd = new OleDbCommand("UPDATE LOGIN SET CPoints='" + tt + "' WHERE U_name = '" + txtusername.Text + "'", con);
con.open
cmd.ExecuteNonQuery
con.Close();
 
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