请教access中的查询问题
在access中建一查询s1如下:
SELECT bz, zh, km, SWITCH(Mid(km,1,2)= '50 ',brfsj,Mid(km,1,2)= '51 ',bryej,True,brfsd) AS brfs
FROM RJ
WHERE km like '5* '
ORDER BY bz, km, zh
c#中执行查询:
库连接上之后
DataSet ds = new DataSet();
OleDbDataAdapter ad = new OleDbDataAdapter( "select * from s1 ", conn);
ad.Fill(ds, "RJ ");
DataGridView1.DataSource = ds.Tables[ "RJ "].DefaultView;
在access 2000 和 2003中直接运行查询s1都可以查询出数据
但在c#中执行后,DataGridView1中没有任何数据
小弟初学,实在不明白....是不是 "select * from s1 "这里的问题?不能这样查询?
可是
SELECT bz, zh, km, SWITCH(km= '167050 ',brfsj,km= '236050 ',brfsd) AS brfs, SWITCH(km= '167050 ',bryej,km= '236050 ',bryed) AS brye
FROM RJ
WHERE km In ( '167050 ', '236050 ')
ORDER BY bz, km, zh;
这条access中的查询用上述c#代码在DataGridView1中却能正确查询出数据
迷糊~~~~
------解决方案--------------------很奇怪的问题啊,把*改成%试试。
SELECT bz, zh, km, SWITCH(Mid(km,1,2)= '50 ',brfsj,Mid(km,1,2)= '51 ',bryej,True,brfsd) AS brfs
FROM RJ
WHERE km like '5% '
ORDER BY bz, km, zh
------解决方案--------------------在程序中,通配符应该是 "% ",而不是 "* "...