Dropdownlist
I am having a table in that i store different user names and passwords. What i need is when i load the page all the users in the table should be displayed in Dropdownlist and when i click on log in button it should verify whether correct password is given to the selected user or not an it should log in...

Niradhip ChakrabortyPosted May 25, 2009, 2:06 AM
For button Click you may refer following code:
bool blnFound = false;
SqlConnection sqlCon = null;
sqlCon = new SqlConnection(ConfigurationManager.AppSettings["con"].ToString());
sqlCon.Open();
SqlCommand cmd = new SqlCommand("select * from Users where", sqlCon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
//validating user name
if (dr["usr_vch_Name"].ToString() == cboUserName.Value)
{
// validating password
if(dr["usr_vch_Password"].ToString()).ToString() == txtPassword.Text)
{
blnFound = true;
// User validated successfully, code redirect to other pages
}
}
}
Dorababu MekaPosted May 23, 2009, 5:04 AM
Kirtan PatelPosted May 23, 2009, 4:05 AM
Then Code Will be Like Below
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("select Username From Users", con);
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
ddlUsers.Items.Add(reader["Username"].ToString());
}
}
}