How to build where clause in MS SQL??

Posted by Kai on Stack Overflow See other posts from Stack Overflow or by Kai
Published on 2010-06-18T04:02:51Z Indexed on 2010/06/18 4:13 UTC
Read the original article Hit count: 164

Filed under:
|
|

I would like to build the where clase of sql statement dynamatically from hashtable in C#.
The key of the hash_table will be the column's name to be inserted and the value of hash_table will be value.

string sql_1="SELECT COL_1,COL_2 FROM MY_TABLE";
string sql_2="SELECT * FROM MY_TABLE WHERE COL_3='ABC'";  //note: some statment have where clause while some do NOT have. 

string sql= ToSql(sql_1,myHashTable); // the actual sql statment will be returned from ToSql
//execute sql
sql= ToSql(sql_2,myHashTable); // 
//execute sql

My Question is, how can I create function ToSql() function in LINQ?
NOTE: The data type of the value of hashtable will be taken into consideration.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql