string Country = "UK";
string City = "London";
using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=sa"))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = 60;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select count(*) From [Customers] Where Country=@Country And City=@City";
cmd.Parameters.Add(new SqlParameter("@Country",Country));
cmd.Parameters.Add(new SqlParameter("@City",City));
conn.Open();
Response.Write(cmd.ExecuteScalar());
}在SQL 事件探查器中看到的结果为:
exec sp_executesql N'Select count(*) From [Customers] Where Country=@Country And City=@City', N'@Country nvarchar(2),@City nvarchar(6)', @Country = N'UK', @City = N'London'
评论(0)
暂无评论。