title: cannot apply indexing with to an expression of type 'system.data.datatable'
body: <p>I have a <code>Login</code> table in SQL Server 2008 and I want to check for a valid user in DataColumn.</p>
  
  <p>I was trying to retrieve value from DataColumn by indexing, but got the error..</p>
  
  <blockquote>
    <p>cannot apply indexing with to an expression of type 'system.data.datatable'.</p>
  </blockquote>
  
  <p>Here is the code:</p>
  
  <pre><code> string connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=DRZare;Integrated Security=true;";
   SqlConnection LOGINCONNECTION = new SqlConnection(connectionString);
  
   string commandText = "select * from Login where UserName = @User and Password = @Pass";
   SqlCommand cmdlogin = new SqlCommand(commandText,    LOGINCONNECTION);
  
   cmdlogin.Parameters.AddWithValue("@User", TextBox5.Text);
   cmdlogin.Parameters.AddWithValue("@Pass",TextBox6.Text);
  
   LOGINCONNECTION.Open();
   DataTable logintable = new DataTable();
   logintable.Load(cmdlogin.ExecuteReader());
  
   for (int i = 0; i &lt; logintable.Rows.Count; i++ )
   {
       User = Convert.ToString(logintable[i]["UserName"]);
       string Pass = Convert.ToString(logintable[i]["Password"]);
   }
  </code></pre>
  
  <p>Help me out.</p>