views:

57

answers:

1

I have a table A which contains a column called LastStartTime with datetime type and I have a store procedure sp_XX which is used to query the table's value

following is the content of sp:

SELECT upper(cast(Id as nvarchar(36))) as 'Id',
   [Name],
   [Description],
   LastStartTime,
 FROM A
 RETURN

Here is the related code

   public DataSet GetXXList()
    {

        DataSet ds = new DataSet("XXList");
        SqlDataAdapter dataAdapter = new SqlDataAdapter();
        SqlConnection conn = GetDbConnection();
        SqlCommand cmd = new SqlCommand();

        cmd.CommandTimeout = conn.ConnectionTimeout;

        try
        {

            conn.Open();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            dataAdapter.SelectCommand = cmd;

            cmd.CommandText = "sp_XX";
            dataAdapter.Fill(ds);

        }
        catch( Exception excep )
        {
            throw new Exception(...);

        }
        finally
        {
            if ( conn != null )
                conn.Close();
        }
        return(ds);

    }

here is the related code that calls the above function:

        DataSet ds = new DataSet("XXList");
        ds = GetXXList();

        DataTable table = ds.Tables[0];

        // adding new columns 
        table.Columns.Add("xxx");
        table.Columns.Add("yyy");
        . . .

        foreach(DataRow row in table.Rows)
        {
             // Log the value to file here !!
             LogValue(string.Format("############## row[LastStartTime]=[{0}]", row["LastStartTime"]));
             LogValue(string.Format("############## row.LastStartTime[{0}]", row.ItemArray[3]));

after logged the value for the datetime field to a file, the date time value will be truncated as following: suppose the value in database is 2010-7-15 04:20:00, then the value logged in file will be 2010-7-15 4

But if execute the stored procudure in SQL server query window, the value returned is correct

Any help will be appreciate!


After some investigations I doubt it is caused by the DateTime.ToString function, I have searched MSDN, when the DateTime.ToString is called without format string, the general format specifier 'G' is used, and 'G' means short date and long time, and long time format seems is set by the culture, so I am wondering if there is a culture whose long time format is just H or %H (without minutes and seconds parts)

Another thing I forget to mentioned is the above functions are called in Web Service, and I found that there is also an option about the time format in ASP.NET Configuration Settings (IIS-> Default Web Site->Properties-> ASP.NET->Edit global config-> Application tab-> Culture), I am not sure if it can cause the DateTime.ToString to output a string as 2010-7-15 4

A: 

What's your data type on LastStartTime?

What is row["LastStartTime"]?

Is LogValue limited in the amount of output?

Cade Roux
What's your data type on LastStartTime? -- it is datetime type# What is row["LastStartTime"]? -- the value is also truncated# Is LogValue limited in the amount of output? -- No
Carlos_Liu
@Carlos_Liu How can Row["LastStartTime"] be truncated? Why isn't it also a datetime (in a dataset)?
Cade Roux
@Cade Roux I am also wondering about this
Carlos_Liu