我有一个存储过程可以计算值在数据库中的次数。但是当它到达时for循环中的代码
tf.layers
循环停止并要求为@ invoice2提供参数。
存储过程:
(int)command.ExecuteScalar();
代码背后:
select count(*) as CountInvoice where invoice1=@invoice1 or @invoice2=@invoice`2
答案 0 :(得分:0)
将这两个参数都考虑在内,这样的工作效果会更好吗?
select count(*) as CountInvoice where invoice1=@invoice1 or invoice2=@invoice2
using (SqlCommand command = new SqlCommand("sp_Count", conn))
{
foreach (TextBox textBox in placehldr1.Controls.OfType<TextBox>())
{
count1 += 1;
count2 += 1;
command.CommandType = CommandType.StoredProcedure;
string invoice = textBox.Text.TrimEnd();
string parameter1 = string.Format("@invoice1", count1);
string parameter2 = string.Format("@invoice2", count2);
command.Parameters.AddWithValue(parameter, invoice);
int invoiceCount = (int)command.ExecuteScalar();
if (invoiceCount > 0)
{
lblError.Text = "Invoice number already exist";
return;
}
command.Parameters.Clear();
}