0
<
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();
    }
}

/>
3
Contributors
2
Replies
18
Views
3 Years
Discussion Span
Last Post by Santanu Das
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.