在对ACCESS进行查询的时候,如果按照下面的方法进行有参数的查询
Code
/// <summary>
/// 执行查询语句,返回DataSet
/// </summary>
/// <param name="SQLString">查询语句</param>
/// <returns>DataSet</returns>
public static DataSet Query(string SQLString, params OleDbParameter[] cmdParms)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
{
DataSet ds = new DataSet();
try
{
da.Fill(ds, "ds");
cmd.Parameters.Clear();
}
catch (System.Data.OleDb.OleDbException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
}
那么就需要我们除了传入SQL文之外,还需要传入OleDbParameter参数
具体可以为:
Code
OleDbParameter par1 = new OleDbParameter();
par1.ParameterName = "@RATE_NAME";
par1.Value = "11";
DataSet ds = DbHelperACE.Query("SELECT * FROM TB_RATE WHERE RATE_NAME = @RATE_NAME", par1);