title: The SelectCommand property has not been initialized before calling 'Fill'. in WinForm
body: <p>I am building a windows application using C#. In my login form, I'm getting <em>Select Command property has not been initialized before calling fill method</em>.</p>
  
  <p>Here is the code:</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>