<
Hi All,

i'm new to this can u please tell me this how can i retrieve username and password from mysql db using asp.net ....

**this is my aspx.cs page** i write this code but it doesn't retreive those things... 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;
using MySql.Data.MySqlClient;


public partial class _Default : System.Web.UI.Page


    {



    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MySqlConnection con = new MySqlConnection("Server=CLU-SERVER;Port=3006;Database=realestate_internal;Uid=mysql;Pwd=;");
        MySqlCommand com = new MySqlCommand("RetrieveEmailPass", con);
        com.CommandType = CommandType.StoredProcedure;
        MySqlParameter p1 = new MySqlParameter("@userName", TextBox1.Text);
        com.Parameters.Add(p1);
        con.Open();
        MySqlDataReader dr = com.ExecuteReader();
        if (dr.Read())
        {
            Label1.Text = "Password is:  " + dr[0].ToString();
        }
        else
        {
            Label1.Text = "User Name does not exist";
        }
        con.Close();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        MySqlConnection con = new MySqlConnection("Server=CLU-SERVER;Port=3006;Database=realestate_internal;Uid=mysql;Pwd=;");
        MySqlCommand com = new MySqlCommand("RetrieveEmailPass", con);
        com.CommandType = CommandType.StoredProcedure;
        MySqlParameter p1 = new MySqlParameter("@userName", TextBox1.Text);
        com.Parameters.Add(p1);
        con.Open();
        MySqlDataReader dr = com.ExecuteReader();
        if (dr.Read())
        {
            Label1.Text = "Email is:  " + dr[1].ToString();
        }
        else
        {
            Label1.Text = "User Name does not exist";
        }
        con.Close();
    }
}

/>

Do you get the message "user name does not exist" or does something else happen? Any error messages?

I am try to posting here, though I do not work with Asp.Net. I am working on vb.Net. Where you are making a condition like if (dr.Read()), in vb we are first checking that the DataReader has any rows.

If dr.HasRows then
    dr.Read()
    'Statements
EndIf

Hope you should get a clue from my post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.