Pass variables with values to postgresql database-Collection of common programming errors

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 ‘cannot find unknown column imagepath’, 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?

string imagepath = ofd.FileName;
string connect = ("Server=localhost;Port=1006;Database=collegestudents;Uid=roberto;Pwd=****;");
MySqlConnection con = new MySqlConnection(connect);
string Query = ("UPDATE student SET studentpix = @imagepath WHERE pk_studentID = '?' OR pk_studentID = pk_studentID "); 
MySqlCommand cmd = new MySqlCommand(Query, con);
cmd.Parameters.AddWithValue("@imagepath",ofd.FileName);   
  1. For postgresql parameters are prefixed with : and not @, try this

    string Query = ("UPDATE student SET studentpix = :imagepath WHERE pk_studentID = '?' OR pk_studentID = pk_studentID "); 
    MySqlCommand cmd = new MySqlCommand(Query, con);
    cmd.Parameters.AddWithValue("imagepath",ofd.FileName);   
    

Originally posted 2013-11-09 23:33:36.