C# Sql参数化 in like

【in】

string sql = "exec('select * from bid where id in ('+@IDS+')')";
System.Data.SqlClient.SqlParameter[] sp = new System.Data.SqlClient.SqlParameter[]
{
new System.Data.SqlClient.SqlParameter("@IDS","1,2,3,4,5,6,7,8")
};
System.Data.DataTable dt = SqlServerHelper.GetDataSet(sql, "PT", sp).Tables[0];

 

【like】

string sql2 = "select * from bid where id like '%'+@ID+'%'";
System.Data.SqlClient.SqlParameter[] sp2 = new System.Data.SqlClient.SqlParameter[]
{
new System.Data.SqlClient.SqlParameter("@ID","8")
};
System.Data.DataTable dt2 = SqlServerHelper.GetDataSet(sql2, "PT", sp2).Tables[0];

posted @ 2015-06-03 16:33  J.Y  阅读(2176)  评论(0编辑  收藏  举报