1

私はこのストアドプロシージャを持っています:

CREATE PROCEDURE SearchEmployee
@EmployeeID int,
@EmployeeName nvarchar(256),
@Address nvarchar(256),

AS

Select EmployeeId, EmployeeName, Address 
From Employee
Where
EmployeeID = @EmployeeID OR
EmployeeName LIKE '%' + @EmployeeName+ '%' OR
Address LIKE '%' + @Address+ '%' 

それから私のWinformsで私はそれを呼び出しますcomboBox1.Text=ALL

using (SqlCommand mySqlCommand1 = new SqlCommand("dbo.SearchEmployee", myDatabaseConnection))
  {
  mySqlCommand1.CommandType = CommandType.StoredProcedure;
  if (comboBox1.Text == "ALL")
        {
         mySqlCommand1.Parameters.AddWithValue("@EmployeeID", textBox1.Text);
         mySqlCommand1.Parameters.AddWithValue("@EmployeeName", textBox1.Text);
         mySqlCommand1.Parameters.AddWithValue("@Address", textBox1.Text);
        }
  }

今、私はどのようにそれを行うのですかcomboBox1.Text=EmployeeID

このようなもの : ?

      if (comboBox1.Text == "ALL")
        {
         mySqlCommand1.Parameters.AddWithValue("@EmployeeID", textBox1.Text);
         mySqlCommand1.Parameters.AddWithValue("@EmployeeName", novalue);
         mySqlCommand1.Parameters.AddWithValue("@Address", novalue);
        }
4

2 に答える 2

0

DbNull.Value (名前空間システム) を探していると思います。

if (comboBox1.Text == "EmploueeID")
{
   mySqlCommand1.Parameters.AddWithValue("@EmployeeID", textBox1.Text);
   mySqlCommand1.Parameters.AddWithValue("@EmployeeName",DbNull.Value);
   mySqlCommand1.Parameters.AddWithValue("@Address", DbNull.Value);
}
于 2013-08-13T15:00:24.127 に答える
0

System.DBNull.Value次のように使用します。

mySqlCommand1.Parameters.AddWithValue("@EmployeeName", System.DBNull.Value);
于 2013-08-13T14:59:41.097 に答える