所以在 C# 中的后台代码中,我有一个 Select 语句:
Select username from vw_members where username = 'SomeValue'
但这在我的aspx页面上返回此错误:列"用户名"不存在
如果我在 pgAdmin SQLEditor 中运行相同的语句,它运行没有问题
如果我在我的隐藏代码上运行这样的东西:
Select username from tbl_users where username = 'SomeValue'
运行正常。
该视图是与用户表和成员表的连接。这是我的 C# 代码:
string selectstmt = "Select UserName from vw_members where UserName = 'SomeValue'";
我在 pgAdmin 中的视图如下所示:
SELECT tbl_member.usertype AS "usertype",
tbl_member.userid AS "userid",
tbl_member.createdate AS "createdate",
tbl_member.lastlogindate AS "lastlogindate",
tbl_member.email AS "email",
tbl_users.userid AS "usersid",
tbl_users.username AS "username",
tbl_users.lastactivitydate AS "lastactivitydate"
FROM tbl_users,
tbl_member
WHERE tbl_users.userid = tbl_member.userid;
有人建议我看看是否启用了区分大小写的列排序规则,结果是它已启用。从那里我确保我的所有列名称在同一个情况下匹配,之后一切正常。
尝试在视图中使用显式联接:
SELECT tbl_member.usertype AS "usertype",
tbl_member.userid AS "userid",
tbl_member.createdate AS "createdate",
tbl_member.lastlogindate AS "lastlogindate",
tbl_member.email AS "email",
tbl_users.userid AS "usersid",
tbl_users.username AS "username",
tbl_users.lastactivitydate AS "lastactivitydate"
FROM tbl_users LEFT OUTER JOIN tbl_member
ON tbl_users.userid = tbl_member.userid
可能没有任何区别,但这是值得尝试的。