如何使用 LINQ 过滤空文本框?
How to filter empty textboxes with LINQ?
我的面板中有 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);
}
}
}
}
var myTextBoxes = HashboardPanel.Controls
.OfType<TextBox>()
.Where(tb => !string.IsNullOrWhitespace(tb.Text));
我的面板中有 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);
}
}
}
}
var myTextBoxes = HashboardPanel.Controls
.OfType<TextBox>()
.Where(tb => !string.IsNullOrWhitespace(tb.Text));