简体   繁体   中英

C# vs SQLEditor — Npgsql.PostgresException 42703: column “username” does not exist

So on my behind code in C# I have a Select Statement:

Select username from vw_members where username = 'SomeValue'

But that returns this error on my aspx page:column "username" does not exist

If I run that same statement in the pgAdmin SQLEditor it runs no problem

If I run something like this on my behind code:

Select username from tbl_users where username = 'SomeValue'

Runs fine.

The view is a join with the user table and a members table. here is my C# code:

string selectstmt = "Select UserName from vw_members where UserName = 'SomeValue'";

My View in pgAdmin looks like:

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;

It was suggested I have a look to see if case sensitive column collation was enabled and turns out it is enabled. From there I made sure all my column names match in the same case, after that everything is working.

Try using an explicit join in your view:

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

May not make any difference, but it is something to try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM