-1

I need your help to figure out and maybe solve this problem.

I have a DataReader and when use the function GetDateTime, to read a Date column, I get the min value. I don't see a GetDate function. I tried changing the datatype of the column to Datetime, in order to both have the same datatype, but it's the same result.

This is the definition of the table:

CREATE TABLE [dbo].[Solped](
    [docNumber] [int] NOT NULL,
    [docType] [nvarchar](255) NOT NULL,
    [createDate] [date] NULL,
    [hora] [time](2) NULL,
    ....

This is where I read the database:

string sql = "SELECT * FROM Solped order by docNumber DESC";
            System.Console.WriteLine(sql);
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                solped = new Solped();

                solped.docNumber = reader.GetInt32(0);
                solped.docType = reader.GetString(1);

                DateTime dt = reader.GetDateTime(2);
                solped.fecha = dt;

This is the value presented when debbuging:

dt = {1/1/0001 12:00:00 AM}

And this is the presented value in the program:

Date(1345089600000)

I am totally confused about that I don't know what function or actions should I take to solve the problem. If you may help, I would greatly appreciate that. Thanks!

Sterling Diaz
  • 3,789
  • 2
  • 31
  • 35

1 Answers1

0

Look like you have the date and the time in two different columns in your table, try this

SELECT DocNumber, DocType, 
CAST(CAST(createDate as varchar(10)) + ' ' + CAST(hora as varchar(12)) as datetime) as fullDate
FROM Solped
saul672
  • 737
  • 5
  • 6
  • Yes, they are in two different columns. I will put them in one if that is better. But the date is null when I use the getDateTime function of the DataReader. – Sterling Diaz Aug 17 '12 at 14:47
  • then you should check if there's ANY record in your table that has this column with a NULL value. – saul672 Aug 17 '12 at 15:03
  • No. There isn't. All are filled. – Sterling Diaz Aug 17 '12 at 20:31
  • Then I don't see why this doesn't work, but maybe you can try something like `dt = DateTime.TryParse(reader.getString(2))` (get it as a string and do the parse after), good luck – saul672 Aug 17 '12 at 21:07