Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In Npgsql there is <a href="http://npgsql.projects.postgresql.org/docs/api/Npgsql.NpgsqlDataReader.html" rel="nofollow"><code>NpgsqlDataReader</code></a> class to retrieve inserted rows, e.g:</p> <pre><code>NpgsqlConnection conn = new NpgsqlConnection(connStr); conn.Open(); NpgsqlCommand insertCmd = new NpgsqlCommand("INSERT INTO binaryData (data) VALUES(:dataParam)", conn); NpgsqlParameter param = new NpgsqlParameter("dataParam", NpgsqlDbType.Bytea); byte[] inputBytes = BitConverter.GetBytes((int)0); Console.Write("Input:"); foreach (byte b in inputBytes) Console.Write(" {0}", b); Console.WriteLine(); param.Value = inputBytes; insertCmd.Parameters.Add(param); insertCmd.ExecuteNonQuery(); NpgsqlCommand selectCmd = new NpgsqlCommand("SELECT data FROM binaryData", conn); NpgsqlDataReader dr = selectCmd.ExecuteReader(); if(dr.Read()) { Console.Write("Output:"); byte[] result = (byte[])dr[0]; foreach(byte b in result) Console.Write(" {0}", b); Console.WriteLine(); } conn.Close(); </code></pre> <p>Result from C# app:</p> <pre><code>Input: 0 0 0 0 Output: 0 0 0 0 </code></pre> <p>Result from pgAdmin:</p> <pre><code>"\000\000\000\000" </code></pre> <p><strong>EDIT:</strong></p> <p>I found explanation why you getting:</p> <pre><code>92 48 48 48 48 48 48 48 48 </code></pre> <p>I checked my code with <strong>previous version</strong> <code>Npgsql2.0.10-bin-ms.net3.5sp1.zip</code> and get above result (of course pgAdmin returns <code>\000\000\000\000</code>), so I think that best what you can do is to use another version without this bug.</p> <p><strong>ANSWER:</strong> User higher version of Npgsql than 2.0.10</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload