小弟搞不定,希望各位帮帮忙!
我读取数据库代码:
cs:
string strSel = "select user.*,info.* from user left join info on user.ID = info.userID where (info.type='企业标志' or info.type is null)";
aspx:
<%# DataBinder.Eval(Container.DataItem, "id") %> 请问,我这里的id该怎么取?直接用id报错,用user.id也报错,请问我该怎么写呢?
<%# DataBinder.Eval(Container.DataItem, "单位名称") %>
问题点数:30、回复次数:11Top
1 楼WeekZero(∮小气的鬼∮)回复于 2005-08-02 08:41:41 得分 2
把sql语句变换一下吧,读取的数据集中只有一个id就可以这样用了Top
2 楼flashasp(flashasp)回复于 2005-08-02 08:48:16 得分 9
前面改成
select user.id as id from user
user left join info on user.ID = info.userID
where (info.type='企业标志' or info.type is null
即可,因为你只用到IDTop
3 楼flashasp(flashasp)回复于 2005-08-02 08:49:03 得分 0
前面改成
select user.id as id from user
left join info
on user.ID = info.userID
where (info.type='企业标志' or info.type is null)
即可,因为你只用到ID
Top
4 楼jerry_yuan(jerry)回复于 2005-08-02 08:50:23 得分 5
在sql中把所有列列出来,如有两个id 用as 换转列名如:select user.id as uid ……Top
5 楼gxsz()回复于 2005-08-02 08:50:44 得分 0
哦,楼上的各位,我没有仅用到ID,也用到了其他字段,在这里为了大家方便,所以简化了Top
6 楼adandelion(水源是CSDN最黑的地方,但这个最黑是CSDN一手制造的!)回复于 2005-08-02 08:51:59 得分 5
把需要显示的字段都写出来,并且给上别名.而不用user.*之类的语句.这样数据绑定的时候绑定别名就可以了.
Top
7 楼adandelion(水源是CSDN最黑的地方,但这个最黑是CSDN一手制造的!)回复于 2005-08-02 08:54:47 得分 0
select user.id as id ,user.age as age,user.address as address,.....,info.type as tyoe,info.id as infoid,... from user
left join info
on user.ID = info.userID
where (info.type='企业标志' or info.type is null)
Top
8 楼flashasp(flashasp)回复于 2005-08-02 08:58:49 得分 2
一句话,要加AS程序才不会报错
as id,.........Top
9 楼jimu8130(火箭的未来在哪里?)回复于 2005-08-02 09:44:49 得分 1
绑定的名字要在查询得到的结果中一致Top
10 楼rubygmm(itren)回复于 2005-08-02 10:00:13 得分 5
select user.id as id from user
left join info
on user.ID = info.userID
where (info.type='企业标志' or info.type is null)
绑定的名字要与在查询得到的结果中一致Top
11 楼fphuang(人在哈尔滨·四月)回复于 2005-08-02 10:07:33 得分 1
如果是Access数据库的话,用id as xxid也白费,修改数据库字段吧Top




