我有一个PostgreSQL数据库,想要查询表"Locations"以检索与用户输入的名称匹配的所有位置名称。 列名为"LocationName"。 我正在使用ASP.net和C#。
NpgsqlConnection con = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ToString());
NpgsqlCommand cmd = new NpgsqlCommand("Select * from \"Locations\" where \"LocationName\" LIKE \"%@loc_name%\"", con);
cmd.Parameters.AddWithValue("@loc_name", Location_Name);
NpgsqlDataReader reader = cmd.ExecuteReader();
我遇到了这个异常:
Npgsql.NpgsqlException: ERROR: 42703: column "%((E'My place'))%" does not exist
我尝试运行查询,没有使用%,但是它不起作用。 我还尝试使用+和&,如下所示,但也没有起作用:
string query = "Select \"LocationName\" from \"Locations\" where \"LocationName\" LIKE '%'+ :loc_name +'%'";
使用上述代码行,我遇到了以下异常:
Npgsql.NpgsqlException: ERROR: 42725: operator is not unique: unknown + unknown