title: Running sql SubQueries in asp.net c#
body: <p>hello everyone i am working on mycollege project and trying to make a user login application in asp.dot net.
  I have two tables in my database one is customer full detail and other is customer login detail
  What I want to do to count the row in first query and if login_id and password matches then it executes the other query to retrive and displays the customer first name, on the redirectedd page 
  below is what i have done any other type of  method is also welcomed 
  here is my code</p>
  
  <pre><code>protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
  {
      SqlConnection connection = new SqlConnection(conn);
      connection.Open();
      cmd = new SqlCommand("select COUNT(*) from customer_login where login_id = @a and pass_login=@b",connection);
      cmd.Parameters.AddWithValue("@a", Login1.UserName);
      cmd.Parameters.AddWithValue("@b", Login1.Password);
      string user_name;
      int i = Convert.ToInt32(cmd.ExecuteScalar().ToString());
      if (i == 1)
      {
          e.Authenticated = true;
          cmd = new SqlCommand("select f_name from customer where id = (select cust_id from customer_login where login_id = @a)", connection);//This query successfully runs in mssms but it gives error in aspx
        // cmd.Parameters.AddWithValue("@c",new SqlCommand ("select cust_id from customer_login where login_id = @a"));
        //cmd.Parameters.AddWithValue("@a", Login1.UserName);
  
          sdr = cmd.ExecuteReader();
          sdr.Read();
          user_name = sdr["f_name"].ToString();
          sdr.Close();
          if (Session["productID"] != null)
          {
              Session["user"] = user_name.ToString();
              Response.Redirect("~/Detail/cart.aspx");
          }
          else
          {
              Response.Redirect("Default.aspx");
          }
      }
      else
      {
          e.Authenticated = false;
      }
  
  } 
  </code></pre>
  
  <p>the problem is it gives following error "Incorrect syntax near the keyword 'select'.
  Must declare the scalar variable "@a". "
   thanku</p>