<br><br><div class="gmail_quote">2009/12/16 George  Vlahakis <span dir="ltr"><<a href="mailto:g.vlahakis@telenavis.com">g.vlahakis@telenavis.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">









<div link="blue" vlink="purple" lang="EL">

<div>

<p class="MsoNormal"><span style="font-size: 10pt; color: rgb(15, 36, 62);" lang="EN-US">Hi Emilie,</span></p>

<p class="MsoNormal"><span style="font-size: 10pt; color: rgb(15, 36, 62);" lang="EN-US"> </span></p>

<p class="MsoNormal"><span style="font-size: 10pt; color: rgb(15, 36, 62);" lang="EN-US">Im trying to port over to npgsql but I cannot get the GeomFromWKB
function to get called correctly. No matter what I do with the wkb parameter the
query failes (error near \”,\”). Any hints?</span></p>

<p class="MsoNormal"><span style="font-size: 10pt; color: rgb(15, 36, 62);" lang="EN-US"> </span></p>

<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                <span style="color: rgb(64, 0, 128);">const</span> <span style="color: rgb(64, 0, 128);">string</span> <span style="color: rgb(1, 0, 1);">sql</span> <span style="color: rgb(46, 83, 209);">=</span> <b><span style="color: rgb(37, 146, 65);">"INSERT INTO
table ("</span></b><span style="color: rgb(37, 146, 65);"></span></span></p>

<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                                   <span style="color: rgb(46, 83, 209);">+</span> <b><span style="color: rgb(37, 146, 65);">"client,
category, description, geom)"</span></b><span style="color: rgb(37, 146, 65);"></span></span></p>

<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                                   <span style="color: rgb(46, 83, 209);">+</span> <b><span style="color: rgb(37, 146, 65);">" VALUES (?,
?, ?, GeomFromWKB(?, 4326)) RETURNING id"</span></b>;</span></p>

<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US"> </span></p>


<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                <span style="color: rgb(1, 0, 1);">cmd</span> <span style="color: rgb(46, 83, 209);">=</span> <span style="color: rgb(64, 0, 128);">new</span> <span style="color: rgb(48, 95, 182);">NpgsqlCommand</span>(<span style="color: rgb(1, 0, 1);">sql</span>,
<span style="color: rgb(1, 0, 1);">conn</span>);</span></p>

<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                <span style="color: rgb(1, 0, 1);">cmd</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Parameters</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Add</span>(<span style="color: rgb(64, 0, 128);">string</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Empty</span>, <span style="color: rgb(1, 0, 1);">request</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">ClientId</span>);</span></p>


<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                <span style="color: rgb(1, 0, 1);">cmd</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Parameters</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Add</span>(<span style="color: rgb(64, 0, 128);">string</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Empty</span>, <span style="color: rgb(1, 0, 1);">request</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">CategoryId</span>);</span></p>


<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                <span style="color: rgb(1, 0, 1);">cmd</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Parameters</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Add</span>(<span style="color: rgb(64, 0, 128);">string</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Empty</span>, <span style="color: rgb(1, 0, 1);">request</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Description</span>);</span></p>


<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                <span style="color: rgb(64, 0, 128);">byte</span>[]
<span style="color: rgb(1, 0, 1);">bytes</span> <span style="color: rgb(46, 83, 209);">=</span> <span style="color: rgb(1, 0, 1);">GetWkbPolygon</span>(<span style="color: rgb(1, 0, 1);">request</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Points</span>);</span></p>


<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                <span style="color: rgb(1, 0, 1);">cmd</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Parameters</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Add</span>(<span style="color: rgb(64, 0, 128);">new</span> <span style="color: rgb(48, 95, 182);">NpgsqlParameter</span>(<span style="color: rgb(64, 0, 128);">string</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">Empty</span>, <span style="color: rgb(1, 0, 1);">bytes</span>));</span></p>


<p class="MsoNormal" style="background: rgb(191, 191, 191) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="background: silver none repeat scroll 0% 0%; font-size: 9pt; font-family: "Envy Code R VS"; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;" lang="EN-US">                <span style="color: rgb(64, 0, 128);">int</span> <span style="color: rgb(1, 0, 1);">id</span> <span style="color: rgb(46, 83, 209);">=</span> (<span style="color: rgb(64, 0, 128);">int</span>)<span style="color: rgb(1, 0, 1);">cmd</span><span style="color: rgb(46, 83, 209);">.</span><span style="color: rgb(1, 0, 1);">ExecuteScalar</span>();</span><span style="font-size: 10pt; color: rgb(15, 36, 62);" lang="EN-US"></span></p>
<div class="im">

<p class="MsoNormal"><span style="font-size: 10pt; color: rgb(15, 36, 62);" lang="EN-US"> </span><br></p></div></div></div></blockquote></div>Usually, I use parameters only when I am calling a function. Here is an example<br>
<br> agent.AddParameter("@latitude", this.latitude);<br>agent.AddParameter("@longitude", this.longitude);<br><br>  using (NpgsqlDataReader reader = agent.ExecuteReader("postgisfunction"))<br>
  {<br>    if (reader.HasRows)<br>    {<br>     reader.Read();<br>    }<br>  }<br>}<br><br>In this case, @latitude and @longitude are the name of the parameters for my function in Postgresql. I never write SQL statement directly in code. I hope this will be useful to you.<br>
<br>Emilie Laffray<br>