简体   繁体   English

npgsql,数组和C#运算符不存在:text [] = text

[英]npgsql, arrays and C# the operator does not exist: text[] = text

. I would really appreciate if somebody could help me out to fix this problem 如果有人可以帮助我解决此问题,我将不胜感激

I'm developing an application using npgsql and c# and when i want to retrieve some information from a table which contains a column with an array of elements, the problem starts when I want to use a query like this: 我正在开发使用npgsql和c#的应用程序,当我想从包含有元素数组的列的表中检索某些信息时,当我想使用这样的查询时,问题就开始了:

   NpgsqlCommand cmd = new NpgsqlCommand("select * from book_editions", conn);

the compiler shows the column which contains the elements example({1st,2nd,3d}) as "Data.System.String[] therefore i tried to fix the problem by using parameters.... like is shown here below. 编译器将包含元素example({1st,2nd,3d})的列显示为“ Data.System.String [],因此我尝试通过使用参数来解决此问题。...如下所示。

    NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;User Id=postgres; " +"Password=admin;Database=library_system;");
    conn.Open();

    //////string[] options = new string[] { "marketing", "m" }; already tried and failed

    ArrayList l = new ArrayList();
        l.Add("2th");
        l.Add("3th");

        NpgsqlParameter p = new NpgsqlParameter("parameterlist", NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Text);

        NpgsqlCommand cmd = new NpgsqlCommand("select * from book_editions where editions = any (:parameterlist)", conn);

        //editions is the column which has the array of elements, its datatype is text

        p.Value = l.ToArray();
        cmd.Parameters.Add(p);

     NpgsqlDataReader dr = cmd.ExecuteReader();

     while (dr.Read())

     Console.Write("{0} \n", dr[0].ToString());

     Console.ReadKey();

      conn.Close();

when i execute the code the cmd.ExecuteReader throws this error: 当我执行代码时, cmd.ExecuteReader会引发此错误:

npgsql was unhandled
ERROR: 42883: el operador no existe: text[] = text

i got the following sentence as a tip.... 我得到以下句子作为提示。

Ningún operador coincide con el nombre y el tipo de los argumentos. 宁根州的歌剧院商人与国会议员合影。 Puede ser necesario agregar conversiones explícitas de tipos. Puede ser necesario agregar转换为tipícitasde tipos。 (there is no operator which matches with the name and argument types, it would be required to add explicit type castings (没有与名称和参数类型匹配的运算符,将需要添加显式类型转换

does anybody know the solution? 有人知道解决方案吗? :( :( i already tried hard. :( :(我已经努力了。

Updated: 更新:

   var cmd = new NpgsqlCommand("select array_to_string(column, ', '),othercolumn,othercolumn from table",connection);

   var l = new ArrayList();
   l.Add("2th");
   l.Add("3th");

   cmd.Parameters.Add(new NpgsqlParameter("parameterlist", NpgsqlDbType.Array | NpgsqlDbType.Varchar));      

   cmd.Parameters[0].Value = l.ToArray();

   var dr = cmd.ExecuteReader();

   while (dr.Read())
     Console.Write("{0} \n", dr[0].ToString());

   Console.ReadKey();
   conn.Close();

Try again! 再试一次!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Npgsql.PostgresException (0x80004005): 42883: 运算符不存在: jsonb #> text - Npgsql.PostgresException (0x80004005): 42883: operator does not exist: jsonb #> text 将 Npgsql 文本类型转换为 C# 类型 - Convert Npgsql text type to C# type C#与SQLEditor — Npgsql.PostgresException 42703:“用户名”列不存在 - C# vs SQLEditor — Npgsql.PostgresException 42703: column “username” does not exist 从 C# 调用时,Npgsql.Postgresql 异常 42883 function 不存在 - 是否有可用的工作示例? - Npgsql.Postgresql Exception 42883 function does not exist when called from C# - is there a working example available? 42883:函数不存在-在Entity Framework C#Npgsql中调用Postgres函数 - 42883: function does not exist - Calling Postgres Functions in Entity Framework C# Npgsql PostgreSQL:42883 运算符不存在:没有时区的时间戳 = 文本 - PostgreSQL: 42883 Operator does not exist: timestamp without time zone = text 将文本保存到数组 C# 表单中 - Saving text into arrays C# forms Npgsql 异常:列 c.consrc 不存在 - Npgsql exception: Column c.consrc does not exist C#中是否存在“增量按位移位运算符”? - Does an 'increment bitwise shift operator' exist in C#? 需要帮助C#textBox1.Text在当前上下文中不存在 - Need help C# textBox1.Text does not exist in current context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM