The SelectCommand property has not been initialized before calling 'Fill'. in WinForm
<p><strong>i am building a windows application using C#. in my login form i am getting Select Command property has not been intialized before calling fill method. Here is The code</strong></p>

<p><strong>//this is the code for login Form</strong></p>

<pre><code>public partial class frmlogin : Form
    {
        SqlConnection con = new SqlConnection("Data Source=TH07L019;Initial Catalog=loginerror;Integrated Security=True");
        DataTable dt = new DataTable();
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter adp = new SqlDataAdapter();


        public frmlogin()
        {

            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cmd.Connection = con;


        }

        private void button1_Click(object sender, EventArgs e)
        {

            con.Open();
            cmd.CommandText = "select * from login where username='" + txt1.Text + "' and password='" + txt2.Text +"'";
            adp.Fill(dt);
            if (dt.Rows.Count &gt; 0)
            {
                frmmain main = new frmmain();
                main.Show();
            }
            else
            {
                MessageBox.Show("Please enter correct name and passowrd", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
</code></pre>
