Best practices for inline SQL queries

mzikz

New Member
I'm working with an asp.net website that uses a lot of inline SQL queries... and I'm wondering if it is best to create the inline queries on the fly:\[code\]int i = 500; using (SqlConnection conn = new SqlConnection(connStr)) { SqlCommand com = new SqlCommand(conn); ... com.CommandText = "select from table where column < @parameter"; ... }\[/code\]Or to have a class to hold all queries needed for the application. Something like this:\[code\]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; }}\[/code\]Thank you!
 
Back
Top