{"id":1162,"date":"2022-08-30T15:13:25","date_gmt":"2022-08-30T15:13:25","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/pass-variables-with-values-to-postgresql-database-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:13:25","modified_gmt":"2022-08-30T15:13:25","slug":"pass-variables-with-values-to-postgresql-database-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/pass-variables-with-values-to-postgresql-database-collection-of-common-programming-errors\/","title":{"rendered":"Pass variables with values to postgresql database-Collection of common programming errors"},"content":{"rendered":"<p>I created this method in C# Visual studio 2010.The ofd.Filename is actually a path to a file location on the hard drive. This method connects to a MYSQL database and it works very well. However in Postgresql, the variable imagepath with the @symbol does not get recognised at all. In fact the error message is that &#8216;cannot find unknown column imagepath&#8217;, but imagepath is a value not a column in the database. Enclosing @imagepath in single quotes does not pass the value of ofd.FileName, instead it passes the literal word into the database. Does anyone know of a way of passing the variable value to the database in postgresql?<\/p>\n<pre><code>string imagepath = ofd.FileName;\nstring connect = (\"Server=localhost;Port=1006;Database=collegestudents;Uid=roberto;Pwd=****;\");\nMySqlConnection con = new MySqlConnection(connect);\nstring Query = (\"UPDATE student SET studentpix = @imagepath WHERE pk_studentID = '?' OR pk_studentID = pk_studentID \"); \nMySqlCommand cmd = new MySqlCommand(Query, con);\ncmd.Parameters.AddWithValue(\"@imagepath\",ofd.FileName);   \n<\/code><\/pre>\n<ol>\n<li>\n<p>For postgresql parameters are prefixed with <code>:<\/code> and not <code>@<\/code>, try this<\/p>\n<pre><code>string Query = (\"UPDATE student SET studentpix = :imagepath WHERE pk_studentID = '?' OR pk_studentID = pk_studentID \"); \nMySqlCommand cmd = new MySqlCommand(Query, con);\ncmd.Parameters.AddWithValue(\"imagepath\",ofd.FileName);   \n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:33:36. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I created this method in C# Visual studio 2010.The ofd.Filename is actually a path to a file location on the hard drive. This method connects to a MYSQL database and it works very well. However in Postgresql, the variable imagepath with the @symbol does not get recognised at all. In fact the error message is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1162","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1162"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1162\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}