0

我的面板中有 6 个文本框,但并非所有文本框都会在每次用户提交时填写。如何使用此 LINQ 方法但过滤掉空文本框?

   public void LogHB()
      {
          var myTextBoxes = HashboardPanel.Controls
          .OfType<TextBox>()
          .Where;
          foreach(TextBox txt in myTextBoxes)
          {
             string hbserial = txt.Text;          
             try
             {
                  SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["HMT2DBCS"].ConnectionString);
                  using (SqlCommand command = new SqlCommand("spHBcheckin", connection))
                  {
                       command.CommandType = CommandType.StoredProcedure;
                       command.Parameters.AddWithValue("@order_id", txtorder_id.Text);
                       command.Parameters.AddWithValue("@hbserial", hbserial);
                  }
              }
          }
      }
4

1 回答 1

0
var myTextBoxes = HashboardPanel.Controls
    .OfType<TextBox>()
    .Where(tb => !string.IsNullOrWhitespace(tb.Text));
于 2020-08-06T14:02:44.427 回答