PROBLEM WITH DATE TYPE
Posted: Wed 07 Oct 2009 23:43
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
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