Im trying to query some data from a postgres server using C#.
This is the code im currently working with:
namespace WpfApp1
{
class postgresDB
{
public void Init_database()
{
NpgsqlConnection conn = new NpgsqlConnection("Server=FS01;User Id=postgres;" +
"Password=pwd;Database=postgres;");
conn.Open();
Debug.WriteLine("DB opened");
NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM 'Users';", conn);
NpgsqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
Console.Write("{0}\n", dr[0]);
conn.Close();
Debug.WriteLine("DB closed");
}
}
}
The Problem I have is that the SELECT query errors with this error:
42601: syntax error at or near "'Users'"
Im trying to do this in the first place because the postgres table name needs to be in quotes so it doesnt check the upper/lower case letters of the name. If i put the name in quotes it just skips that and finds the table anyways.
>Solution :
string t = "SELECT * FROM \"Users\";";
or
string t2 = @"SELECT * FROM ""Users"";";
should work