Click here to Skip to main content
15,904,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir,
I am creating forget password page without using Login Controls.

The scenario is: if the email-id submitted by the user matches with the corresponding value in database, then the password can be retrieved in mywebpage.

I have follwing table:

userid    username      usertype     password        mail
9         avinash       admin        123           abcd@gmail.com


And I have written following code in data layer:

C#
public  string    forgotpassword(string mail)
         {
             string  result;
             SqlConnection con = new SqlConnection(connstr);
             if (con.State == ConnectionState.Open)
             {
                 con.Close();
             }
             con.Open();
             SqlDataReader myDataReader;

            SqlCommand cmd = new SqlCommand("select password from tbluser where mail=@mail", con);
            cmd.Parameters.Add("@mail", SqlDbType.VarChar, 50).Value = mail;
            DataSet ds = new DataSet();
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            return result = adp.Fill(ds).ToString() ;
         }


C#
protected void BtnSubmit_Click(object sender, EventArgs e)
   {
       mydatalayer.DataLayer d1 = new mydatalayer.DataLayer();
       d1.forgotpassword(TextBox1.Text);
       Lblpwd.Text = d1.forgotpassword(TextBox1.Text);
        int s = int.Parse(Lblpwd.Text);
}

But the problem is that I didn't get password I need
after submit click if I give the mail id as abcd@gmail.com in textbox. It will retrieve password 123 to label.
Please help!
Posted
Updated 1-Oct-10 2:07am
v3
Comments
Sunasara Imdadhusen 1-Oct-10 8:11am    
what will be output of following line?
adp.Fill(ds).ToString()
balongi 1-Oct-10 8:20am    
i give 1. if it found email in database otherwise it return zero but i want password 123
Sunasara Imdadhusen 1-Oct-10 8:24am    
now you can try my latest answer reply and it is working fine. :)

Hi,

Please make minor change in following line
C#
//return result = adp.Fill(ds).ToString() ;
//Newly added 
return  Convert.ToString(ds.Tables[0]["password"]);


Please do let me know, if you have any doubt.

Please provide "Vote" if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen
 
Share this answer
 
Comments
balongi 1-Oct-10 8:11am    
this error is come after i replaced my coding to your suggestion

Error 1 Cannot apply indexing with [] to an expression of type 'System.Data.DataTable'
Sunasara Imdadhusen 1-Oct-10 8:21am    
return Convert.ToString(ds.Tables[0].Rows[0]["password"]);

This is working on my machine.
balongi 1-Oct-10 8:32am    
Cannot find table 0. this error come
Sunasara Imdadhusen 1-Oct-10 8:38am    
That means the database table dose not having matching value with Email address.
balongi 1-Oct-10 8:43am    
But i am giving matching value to it
this line makes the problem:
int s = int.Parse(Lblpwd.Text);


replace this with below:
string s = Lblpwd.Text;


Please Vote if this helped you then.
 
Share this answer
 
Comments
balongi 1-Oct-10 8:05am    
this is not right because it return o or 1 .. if written email is in database it give 1 otherwise zero.. but i want the password.. that is 123 in my database
NMehta83 1-Oct-10 8:53am    
remove or comment below 2 lines.
SqlDataReader myDataReader;
cmd.Parameters.Add(#Quote#@mail#Quote#, SqlDbType.VarChar, 50).Value = mail;

then tell me the result.
you can't parse an string to an int :)
 
Share this answer
 
Comments
balongi 1-Oct-10 8:34am    
But this is not big issue.. plz observe my issue is related to big problem
balongi 1-Oct-10 8:53am    
string s = Lblpwd.Text;
but problem is not solved

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