首页 新闻 会员 周边

ASP.NET C#语言编程

0
悬赏园豆:15 [已关闭问题]

我是在VS2005中利用C#语言编写的代码,我的表中要实现用户每登陆一次,字段次数就减一,直到次数=0时,就提示:要求用户冲账。

问题补充: protected void Button2_Click(object sender, EventArgs e) { string connstr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True"; SqlConnection coon = new SqlConnection(connstr); coon.Open(); string sql = "update 月卡表 set 次数 = 次数 -1 where 用户名='" + TextBox2.Text.Trim() + "'"; SqlCommand cmd = new SqlCommand(sql, coon); //int n = (int)cmd.ExecuteScalar(); //if (n<=0) //{ // Response.Write("<script>alert('此卡不可用,请冲账')</script>"); //} string SQL = "select count(*) from 月卡表 where 次数='" + TextBox3.Text.Trim() + "'"; SqlCommand CMD = new SqlCommand(SQL, coon); SqlDataReader reader = cmd.ExecuteReader(); GridView2.DataSource = reader; GridView2.DataBind(); reader.Close(); coon.Close(); } 我的代码是这样的,但是在运行时,提示//部分提示:未将对象引用设置到对象的实例。 我到底哪错了?
小猪51的主页 小猪51 | 初学一级 | 园豆:190
提问于:2009-07-24 17:38
< >
分享
其他回答(3)
0

在验证用户成功登录之后,即做一个更新的动作.

update [tableName] set  [times] = [times] -1 where ....

其实每次在登录成功之后,就要做一个检查,看看[times]字段还有多少.还有多少,应提前提醒用户冲账

另外,用户登录之前,也要检查[times]是否为0,如果为true,不能登录才行.

Insus.NET | 园豆:932 (小虾三级) | 2009-07-24 18:28
0

string sql = "update 月卡表 set 次数 = 次数 -1 where 用户名='" + TextBox2.Text.Trim() + "'";

SqlCommand cmd = new SqlCommand(sql, coon); update 语句

string SQL = "select count(*) from 月卡表 where 次数='" + TextBox3.Text.Trim() + "'";

SqlCommand CMD = new SqlCommand(SQL, coon); select 语句

SqlDataReader reader = cmd.ExecuteReader();
GridView2.DataSource = reader;

你把一个update绑定给GridView2了

jeff_sh | 园豆:365 (菜鸟二级) | 2009-07-31 10:38
0

reader不能做为DataSouce的吧

James.Ying | 园豆:1472 (小虾三级) | 2009-07-31 12:05
0

“未将对象引用设置到对象的实例”一般是指 在运用变量的时候没有 new

emery | 园豆:145 (初学一级) | 2009-07-31 16:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册