Page 1 of 1

PROBLEM WITH DATE TYPE

Posted: Wed 07 Oct 2009 23:43
by JORGEMAL
I have a PostgreSQL table with 2 fields of type Date and I want to insert a record but I have not been able to do it. The code at the end of this post is part of a class where "aut_fnac" and "aut_fdec" are the table fields of type date; "this.FechaNac" and "this.FechaDec" are 2 properties of the class that represent the date fields. I have tried to Convert.ToString the properties (and surround them with single quotes) but I get the exception "time zone "a.m." not recognized".

I also display the records of the table in a gridview mapped to a datasource and the select command has to be like this:

SelectCommand="SELECT aut_clave, aut_nombre, to_char(aut_fnac, 'MONTH DD, YYYY') as aut_fnac FROM cat_autores ORDER BY aut_nombre"

Otherwise, the "aut_fnac" column shows time as 12:00:00 a.m.

First, why does the exception talks about "time zone" and the gridview shows time information if the fields' data types are both date only and not timestamp?

Second, how do I insert the record successfully.

I am using Visual Studio 2008 and Visual C#.

String strQuery = "";
strQuery += "INSERT INTO cat_autores (";
strQuery += "aut_nombre, ";
strQuery += "aut_fnac, ";
strQuery += "aut_pais, ";
strQuery += "aut_genero, ";
strQuery += "aut_coment, ";
strQuery += "aut_sexo, ";
strQuery += "aut_fdec ";
strQuery += ") VALUES (";
strQuery += "'" + this.Nombre + "', '";
strQuery += this.FechaNac + ", ";
strQuery += this.Pais + ", ";
strQuery += this.Genero + ", ";
strQuery += "'" + this.Comentario + "', ";
strQuery += "'" + this.Sexo + "', ";
strQuery += this.FechaDec + ")";

Respectfully,
Jorge Maldonado

Posted: Thu 08 Oct 2009 13:48
by Shalex
1. Please refer to http://www.devart.com/forums/viewtopic.php?t=15942 . The Date type of PostgreSQL is mapped to System.DateTime. That's why your aut_fnac column also contains time.

2. Please send us ( http://www.devart.com/company/contact.html ) a small test project with the DDL/DML script to reproduce the problem with the insert command. Also please specify the error text, the version of your dotConnect for PostgreSQL and the version of your PostgreSQL server.