我有这个存储过程:转换数据类型为nvarchar成int
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我这样称呼它:
using (SqlCommand mySqlCommand1 = new SqlCommand("dbo.SearchEmployee", myDatabaseConnection))
{
mySqlCommand1.CommandType = CommandType.StoredProcedure;
{
mySqlCommand1.Parameters.AddWithValue("@EmployeeID", textBox1.Text);
mySqlCommand1.Parameters.AddWithValue("@EmployeeName", textBox1.Text);
mySqlCommand1.Parameters.AddWithValue("@Address", textBox1.Text);
}
}
我将如何避免错误
将数据类型nvarchar转换为int时出错。
当用户输入员工姓名而不是EmployeeID
?
EmployeeID = cast(@EmployeeID as varchar(10))
因为我只用一个searchTextBox会发现每个字段。非常感谢 :) –