简体   繁体   English

反对读取Label / Textbox.text的Sql数据绑定

[英]Sql DataBinding Against Reading Label/Textbox.text

I am trying to bind sql data on textboxes against reading data from label my code is as below: 我试图将文本框上的sql数据绑定为反对从标签读取数据,我的代码如下:

 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 < 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 < ds10.Tables[0].Rows.Count; p++) 
  {
      label11.Text  = Convert.ToString(ds10.Tables[0].Rows[p]["obcat"]);
  }

The label11 bound by sql data and it should display text "Dr" OR "Cr" at a time. label11受sql数据限制,并且应一次显示文本“ Dr”或“ Cr”。

but it's not working as the label11.text not support for bind the data onto textboxes 但它不起作用,因为label11.text不支持将数据绑定到文本框

I have two textboxes as below: 我有两个文本框,如下所示:

Opening Balance/Debit                     Opening Balance/Credit
txtopenbaldr.Text                           txtopenbalcr.Text

There are two textboxes which can databind on above condition: Remember only one textbox should be bind as per condition. 有两个可以在上述条件下进行数据绑定的文本框:请记住,根据条件只能绑定一个文本框。

I am trying the trick but it's fail. 我正在尝试把戏,但失败了。 Suggest the solution. 建议解决方案。

I'm assuming that you simply appended the code for label11.text at the end of your message, but that in reality label11.text is assigned before you try to set txtopenbaldr.Text or txtopenbalcr.Text . 我假设你只是附加的代码label11.text在邮件的结尾,但在现实中label11.text尝试设置之前被分配txtopenbaldr.Texttxtopenbalcr.Text

If that's the case, I would make sure that label11.Text actually has the value Dr or Cr , and not DR or CR , as the comparisons will be case-sensitive. 如果是这样,我将确保label11.Text实际上具有值DrCr ,而不是DRCR ,因为比较将区分大小写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM