C# 与 SQLEditor -- Npgsql.PostgresException 42703: 列 "username" 不存在
C# vs SQLEditor -- Npgsql.PostgresException 42703: column "username" does not exist
所以在我的 C# 后台代码中,我有一个 Select 语句:
Select username from vw_members where username = 'SomeValue'
但是 returns 我的 aspx 上的这个错误 page:column "username" 不存在
如果我 运行 在 pgAdmin SQLEditor 中使用相同的语句 运行 没问题
如果我 运行 在我的后台代码中有这样的东西:
Select username from tbl_users where username = 'SomeValue'
运行良好。
该视图是与用户 table 和成员 table 的联接。
这是我的 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
可能没什么区别,但值得一试。
有人建议我查看是否启用了区分大小写的列整理,结果证明它已启用。从那里我确保我所有的列名在相同的情况下匹配,之后一切正常。
所以在我的 C# 后台代码中,我有一个 Select 语句:
Select username from vw_members where username = 'SomeValue'
但是 returns 我的 aspx 上的这个错误 page:column "username" 不存在
如果我 运行 在 pgAdmin SQLEditor 中使用相同的语句 运行 没问题
如果我 运行 在我的后台代码中有这样的东西:
Select username from tbl_users where username = 'SomeValue'
运行良好。
该视图是与用户 table 和成员 table 的联接。 这是我的 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
可能没什么区别,但值得一试。
有人建议我查看是否启用了区分大小写的列整理,结果证明它已启用。从那里我确保我所有的列名在相同的情况下匹配,之后一切正常。