Esempio n. 1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            try

            {
                int    t;
                String sql = "select * from Admin where username like '" + textBox1.Text + "' and password like '" + textBox2.Text + "'";//The Select query

                td.Rows.Clear();

                //Initializes a new instance of the SqlDataAdapter class with a SelectCommand and a connection string
                adapter = new SqlDataAdapter(sql, con);

                adapter.Fill(td); //Fill the SQL query results in the variable td of type table

                if (td.Rows.Count == 0)
                {
                    MessageBox.Show("Ivalid Username/Password!");
                }
                else
                {
                    AdminPage f = new AdminPage();
                    f.Show();
                    this.Hide();
                }

                textBox1.Clear();
                textBox2.Clear();
            }

            catch (Exception msj)
            {
                MessageBox.Show("Error!");
                MessageBox.Show(msj.ToString());
            }
        }