title: asp.net database connectivity
body: <p>Please take a look at the following code.</p>
  
  <pre><code>protected void Button2_Click(object sender, EventArgs e)
  {
      SqlConnection con = new SqlConnection(constring);
  
      SqlCommand cmd = new SqlCommand();
  
      if (DropDownList3.SelectedItem.Text == "Economy")
      {
          seats = Convert.ToInt32(DropDownList1.SelectedItem.Text);
  
          cmd.Connection = con;
          con.Open();
          cmd.CommandText = "select easeats from flight where fno='" + fn + "'";
         int eds = Convert.ToInt32(cmd.ExecuteScalar());
  
          if (eds &gt; seats)
          {
              Panel2.Visible = true;                //seats available
              cl = DropDownList3.SelectedItem.Text;  
              seat = seats.ToString();
              seats = eds;
          }
          else
          {
              Panel3.Visible = true;         // seats not available 
          }
          con.Close();
      }
  }
  </code></pre>
  
  <p>I am getting error in the line:<code>int eds = Convert.ToInt32(cmd.ExecuteScalar());</code></p>
  
  <p>And the error is</p>
  
  <blockquote>
    <p>error in converting varchar value to datatype int</p>
  </blockquote>
  
  <p>What is wrong with this code?</p>