更改密码代码的问题 [英] problem in change password code
本文介绍了更改密码代码的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我更改密码的代码。我收到了一些错误。我已经在特定的行中标记了它们。请告诉我如何解决它们。
Here is my code for changing password.I am getting some errors.I have marked them in the specific line.Please tell me how can i solve them.
protected void c_button_Click(object sender, ImageClickEventArgs e)
{
string a, b;
SqlConnection con = new SqlConnection();
SqlDataAdapter da = new SqlDataAdapter("select uname,pass from dbo.tbl_users where uname='" + userid.Text + "',password='" + oldp.Text + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Count; i++) //Operator '<' cannot be applied to operands of type 'int' and 'method group'
{
a = ds.Tables[0].Rows["uname"].ToString(); //The best overloaded method match for 'System.Data.DataRowCollection.this[int]' has some invalid arguments & Argument 1: cannot convert from 'string' to 'int'
b = ds.Tables[0].Rows["pass"].ToString();//The best overloaded method match for 'System.Data.DataRowCollection.this[int]' has some invalid arguments & Argument 1: cannot convert from 'string' to 'int'
if (newp.Text == cnewp.Text)
{
if (a == userid.Text && b == oldp.Text)
{
SqlDataAdapter sda = new SqlDataAdapter("update register set Password = '" + newp.Text.Trim() + "' where UserId ='" + userid.Text + "'", con);
sda.Fill(ds);
Response.Write("<script language=Javascript>alert('Your Password Has Been Changed,Please Login With New Password');document.location='/Login.aspx';</script>");
}
else
{
Response.Write("<script language=Javascript>alert('password')</script>");
}
}
else
{
Response.Write("<script language=Javascript>alert('Password do not match')</script>");
}
}
}
:喊叫删除。
推荐答案
错误1:
Error 1:
ds.Tables[0].Count
无效,我怀疑你的意思是
is not valid, I suspect you mean
ds.Tables[0].Rows.Count
错误2和3都是同一个问题:
而不是
Errors 2 and 3 are both the same issue:
Rather than
a = ds.Tables[0].Rows["uname"].ToString()
它应该是以下格式:
It should be of the format:
a = ds.Tables[0].Rows[rownumber][columnname/columnnumber].ToString()
use like this...
protected void c_button_Click(object sender, ImageClickEventArgs e)
{
string a, b;
SqlConnection con = new SqlConnection();
SqlDataAdapter da = new SqlDataAdapter("select uname,pass from dbo.tbl_users where uname='" + userid.Text + "',password='" + oldp.Text + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count ; i++) //Operator '<' cannot be applied to operands of type 'int' and 'method group'
{
a = ds.Tables[0].Rows[i]["uname"].ToString(); //The best overloaded method match for 'System.Data.DataRowCollection.this[int]' has some invalid arguments & Argument 1: cannot convert from 'string' to 'int'
b = ds.Tables[0].Rows[i]["pass"].ToString();//The best overloaded method match for 'System.Data.DataRowCollection.this[int]' has some invalid arguments & Argument 1: cannot convert from 'string' to 'int'
if (newp.Text == cnewp.Text)
{
if (a == userid.Text && b == oldp.Text)
{
SqlDataAdapter sda = new SqlDataAdapter("update register set Password = '" + newp.Text.Trim() + "' where UserId ='" + userid.Text + "'", con);
sda.Fill(ds);
Response.Write("<script language="Javascript">alert('Your Password Has Been Changed,Please Login With New Password');document.location='/Login.aspx';</script>");
}
else
{
Response.Write("<script language="Javascript">alert('password')</script>");
}
}
else
{
Response.Write("<script language="Javascript">alert('Password do not match')</script>");
}
}
}
这篇关于更改密码代码的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文