帮忙看下,谢谢
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings[ "connectionstring "]);
string strsql= "select username from users where username= ' "+Session[ "username "]+ " ' ";
SqlCommand cmd=new SqlCommand(strsql,conn);
conn.Open();
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{ if(Session[ "account "].Equals( "20 "))
{paymessage.Text= "余额不足 ";
play.Visible=false;}
else
{string str= "update users set account=account-5 where username= ' "+Session[ "username "]+ " ' ";
op.exeCommand(str);
str= "insert into caozuo (username,movname,playdate) values ( ' "+Session[ "username "]+ " ', ' "+title.Text+ " ', ' "+time+ " ') ";
op.exeCommand(str);
str= "update movinfo set clickcount=clickcount+1 where movname= ' "+title.Text+ " ' ";
op.exeCommand(str);
paymessage.Text= "扣费成功,请点击播放按钮 ";
play.Visible=true;}
}
else
{
paymessage.Text= "您还没有登陆不能点播 ";
}
这段程序是判断数据库中account的值是否为20,可是却不对,不知道哪里写错了,麻烦高手指点一下if(Session[ "account "].Equals( "20 "))
{ paymessage.Text= "余额不足 ";
play.Visible=false;}这句话没有执行
------解决方案--------------------if(Session[ "account "].ToString() == "20 ")
如果数据库的account字段不为int之类的
最好转化下:
update users set account=cast(account as int)-5
------解决方案--------------------//记得类型转换
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings[ "connectionstring "]);
string strsql= "select username from users where username= ' "+Session[ "username "].ToString()+ " ' ";
SqlCommand cmd=new SqlCommand(strsql,conn);
conn.Open();
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
if(Convert.ToInt32(Session[ "account "]) == 20)
{
paymessage.Text= "余额不足 ";
play.Visible=false;
}
else
{
string str= "update users set account=account-5 where username= ' "+Session[ "username "].ToString()+ " ' ";
op.exeCommand(str);
str= "insert into caozuo (username,movname,playdate) values ( ' "+Session[ "username "].ToString()+ " ', ' "+title.Text+ " ', ' "+time+ " ') ";
op.exeCommand(str);
str= "update movinfo set clickcount=clickcount+1 where movname= ' "+title.Text+ " ' ";
op.exeCommand(str);
paymessage.Text= "扣费成功,请点击播放按钮 ";
play.Visible=true;
}
}
else
{
paymessage.Text= "您还没有登陆不能点播 ";
}