我正在使用一个使用大量内联 SQL 查询的 asp.net 网站......我想知道是否最好动态创建内联查询:
int i = 500;
using (SqlConnection conn = new SqlConnection(connStr))
{
SqlCommand com = new SqlCommand(conn);
...
com.CommandText = "select from table where column < @parameter";
...
}
或者有一个类来保存应用程序所需的所有查询。像这样的东西:
class SqlQueries
{
private string query1 =
"select * from tblEmployees where EmployeeName = @EmployeeName";
private string query2 =
"select * from tblVacation where EmployeeName = @EmployeeName";
public string Query(string s)
{
string str = string.Empty;
switch (s)
{
case "query1":
str = query1;
break;
case "query2":
str = query2;
break;
}
return str;
}
}
谢谢!