我要參數這個在:參數化多或查詢的WHERE子句
select * from myTable where column1='1' or TaxRateRef='18'
弄成這個樣子:
String query = "select * from myTable where "; // column1='1' or column1='18'
var parameters = new List<SqlParameter>();
for(int i = 0; i < data.Rows.Count;i++)
{
blah blah blah
query += " Column1='@column1' or";
parameters.Add(new SqlParameter("@column1", i));
}
但是我得到一個異常
System.Data.SqlClient.SqlException :The variable name '@column1' has already been declared.Variable names must be unique within a query batch or stored procedure.
Incorrect syntax near 'or'.
你能向我們展示在形成查詢後執行的代碼嗎? – Raghu 2014-08-28 04:21:33