Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 0.45 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. dynamic query generated by stored procedure or function
  2. CREATE PROC Search(
  3.   @title VARCHAR(20) NULL, ...
  4. AS SELECT * FROM your_table WHERE (title = @title OR @title IS NULL) etc.
  5.        
  6. public string BuildQuery(string[] columnNames, string tableName)
  7. {
  8. string query = string.Empty;
  9.  
  10. query = "SELECT ";
  11. foreach(string str in columnNames)
  12. query += str + ", ";
  13. query = query.Substring(0, query.Length - 1);
  14. query += " FROM " + tableName;
  15.  
  16. return query;
  17. }