C#怎么用参数方式查询ACCESS数据库?
我的查询方式如下:private void DataBinding()
{
using (OleDbConnection cn = classBase.GetOledbConnection())
{
string sqlText = "SELECT * FROM Goods WHERE FS_GoodsKind=@FS_GoodsKind";
OleDbCommand cmd = new OleDbCommand(sqlText, cn);
cmd.Parameters.Add("@FS_GoodsKind", OleDbType.VarChar).Value = "商品大类";
OleDbDataAdapter sqlDataAdapter = new OleDbDataAdapter(cmd);
dataSet.Clear();
sqlDataAdapter.Fill(dataSet, "Goods");
dgvGoods.DataSource = dataSet.Tables[0].DefaultView;
}
}
可是奇怪的是查不出GOODS表中GoodsKind字段值为"商品大类"的记录,实际是有的,如果WHERER子句换成
WHERE FS_GoodsKind like +'%'+ @FS_GoodsKind+'%'
就可以查出来,但这是模糊匹配啊?
请各位指点一下,谢谢!
[ 本帖最后由 C心情 于 2011-9-14 13:09 编辑 ]