与更新表有关的错误 [英] Error Related to Updating a table

查看:45
本文介绍了与更新表有关的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中..



in my project..

<%@ 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

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..!!";
        }
    }
}



和已使用的访问数据库。



我有两张桌子:

1. coupen

2.登录



coupen 表格字段是:


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,-...


运行页面时的
输入凭证在文本框中没有..并单击提交...单击按钮后,将显示在第二个文本框,在第3个文本框中输入用户名...再次单击提交按钮...



单击按钮时CPoints相关数据将是从coupen中删除并且CPoints将在与U_name相关的LOGIN表中更新..



问题是当我点击提交按钮时第二次登录表格没有更新..



如果你明白我的意思。

plz帮助我...


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...

推荐答案

首先设置参数和对象,然后打开,执行和关闭。

因此,在您的更新中,您打开,什么也没做,然后关闭它。



您可能要考虑将来使用参数



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();


这篇关于与更新表有关的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆