title: Sql DataBinding Against Reading Label/Textbox.text
body: <p>I am trying to bind sql data on textboxes against reading data from  label my code is as below:</p>
  
  <pre><code> string sql1 = " select openbal from AccountMast where accname='" + comboBox1.Text + "' and companyID='" + label4.Text + "'";
  SqlDataAdapter dap1 = new SqlDataAdapter(sql1, con);
  DataSet ds1 = new DataSet();
  dap1.Fill(ds1);
  for (int p = 0; p &lt; ds1.Tables[0].Rows.Count; p++) 
  {
    if (label11.Text == "Dr") 
  {
    txtopenbaldr.Text = Convert.ToString(ds1.Tables[0].Rows[p]["openbal"]);
  
   }
    if (label11.Text == "Cr") 
    {
      txtopenbalcr.Text  = Convert.ToString(ds1.Tables[0].Rows[p]["openbal"]);
    }
  }
  
  
  //Label11 Bind by Sql.
  
  string sql10 = " select obcat from AccountMast where accname='" + comboBox1.Text + "' and companyID='" + label4.Text + "'";
    SqlDataAdapter dap10 = new SqlDataAdapter(sql10, con);
    DataSet ds10 = new DataSet();
    dap10.Fill(ds10);
  
    for (int p = 0; p &lt; ds10.Tables[0].Rows.Count; p++) 
    {
        label11.Text  = Convert.ToString(ds10.Tables[0].Rows[p]["obcat"]);
    }
  </code></pre>
  
  <p>The label11 bound by sql data and it should display text "Dr" OR "Cr" at a time.</p>
  
  <p>but it's not working as the label11.text not support for bind the data onto textboxes</p>
  
  <p>I have two textboxes as below:</p>
  
  <pre><code>Opening Balance/Debit                     Opening Balance/Credit
  txtopenbaldr.Text                           txtopenbalcr.Text
  </code></pre>
  
  <p>There are two textboxes which can databind on above condition: Remember only one textbox should be bind as per condition.</p>
  
  <p>I am trying the trick but it's fail. Suggest the solution. </p>