Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
I am new to wpf. Today i connect the mysql to wpf. now i try to log in the window. but the passwordbox didnot content text propriety. Pls help me to create login form.

private void button1_Click(object sender, RoutedEventArgs e)
        {
            # region Command Method
            string MyConString = "SERVER=192.168.1.100;" + "DATABASE=mcs_kiosk;" + "UID=root;" + "PASSWORD=;";
            MySqlConnection connection = new MySqlConnection(MyConString);
            MySqlCommand command = connection.CreateCommand();
            MySqlDataReader Reader;
            command.CommandText = "select mcs_User_Id from mcs_User";
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
for (int i = 0; i < Reader.FieldCount; i++)
{
textBox1.Text = Reader[i].ToString();
}
}
connection.Close();
            #endregion
}
Posted
Updated 15-Feb-11 18:40pm
v3

passwordBox1.Password=Reader[i].ToString();

check WPF PasswordBox Control[^]
 
Share this answer
 
Comments
Sagotharan Jagadeeswaran 16-Feb-11 1:11am    
thank u sir.
Sandeep Mewara 16-Feb-11 1:18am    
OP wants to get it verified from you. Posted code as an answer.
Sagotharan Jagadeeswaran 16-Feb-11 1:36am    
Thank u very much,.

What is mean OP?.
thank u mkgoud friend.
now my program is correctly working.

Pls Check my Code,. And Give the Feedback,. whether it is a effective code or not?.


private void button1_Click(object sender, RoutedEventArgs e)
       {
           # region Command Method
           string MyConString = "SERVER=192.168.1.100;" + "DATABASE=mcs_kiosk;" + "UID=root;" + "PASSWORD=;";
           MySqlConnection connection = new MySqlConnection(MyConString);
           MySqlCommand command = connection.CreateCommand();
           MySqlDataReader Reader;
           command.CommandText = "select * from mcs_User";
           connection.Open();
           Reader = command.ExecuteReader();

           while (Reader.Read())
           {
               //textBox1.Text = Reader[1].ToString();
               //textBox2.Text = Reader[2].ToString();

               if ((textBox1.Text == Reader[1].ToString()) && (passwordBox1.Password== Reader[2].ToString()))
               {
                   Master mas = new Master();
                   mas.Show();
               }
               else
                   MessageBox.Show("Password or Username not Correct");
           }
           connection.Close();
           #endregion
       }
 
Share this answer
 
Comments
Sandeep Mewara 16-Feb-11 1:19am    
Effective or not? What kind of question is this? Further, use comment feature if you want to interact to some answer.
m@dhu 16-Feb-11 1:26am    
Effective or not? I am not sure what you are asking but hope if your db table contains unique userid/email you can change your query to
select * from mcs_User where userid=@userid
so that instead of reading all rows you can read only those with userid passed.
Sagotharan Jagadeeswaran 16-Feb-11 1:41am    
Thank u very much,. I have no experience to company standard Coding. So any Feedback given to me,. I can also sine WPF. Once again Thank you very much mkgoud,.

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