[英]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.