Opening second form using MySql database
Do you every wanted to make a login like application and you can’t find a way to hide your main form and open a 2nd form?
Now you can easily make it with help of this video and code below.
Very simple and easy steps to make it
try{
string myConnection = "datasource=localhost;port=3306;username-root;password=root";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand SelectCommand = new MySqlCommand("select * from database.edata whereuser_name = '"+this.username_txt.Text+"' and password = '"+this.password_txt.Text+"';",myConn);
MySqlDataReader myReader;
myConn.Open();
myReader = SelectedCommand.ExecuteReader();
int count = 0;
while(myReader.Read())
{
count = count + 1;
}
if(count == 1)
{
this.Hide();
From2 f2 = new Form2();
f2.ShowDialog();
}
else if(count > 1)
{
MessageBox.Show("deplicate username and password");
}
else
{
MessageBox.Show("username and password aren't correct.. please try again");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
The above code is code of the 4th video on C# playlist.
You can copy it and use it to try it.
Leave a Reply