Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
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>");
            }
        } 
     } 


[Edit]:Shouting Removed.
Posted
Updated 2-Jul-13 21:10pm
v2
Comments
Richard MacCutchan 3-Jul-13 2:50am    
The error messages tell you what's wrong; you cannot expect the compiler to automatically convert from one type to another.
Thanks7872 3-Jul-13 3:11am    
All capitals considered as shouting.
dimtdj 3-Jul-13 3:13am    
Rohan Leuva... i m sorry for that but i didn't mean to shout... :)

Error 1:

ds.Tables[0].Count
is not valid, I suspect you mean
ds.Tables[0].Rows.Count


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()
 
Share this answer
 
Comments
Thanks7872 3-Jul-13 3:12am    
Good ones..↑voted.
C#
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>");
            }
        } 
     } 
 
Share this answer
 
v2

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