2011-08-23 25 views
0

很多google搜索和嘗試之後,我還是沒能做到這一點:時間跨度格式讀取來自SQLite的到datGridView

把C#時間跨度值大於24小時爲一個數字SQLite表列,並把它找回來在.NET DataGridView中以正確的格式顯示這些較大的時間跨度值。

如果我做這樣的事情:

cmd.CommandText = "insert into test (s) values (@s)"; 
cmd.CreateParameter<TimeSpan>("s", new TimeSpan(23,59,59)); 

然後

cmd.CommandText = "select time(s) as s from test"; 

,並將結果與​​

我可以在右側看到格式化值23:59:59 DataGridView的鏈接列。

在我放入任何更大的TimeSpan後,列保持空白(沒有錯誤信息),並且沒有其他格式化函數幫助我一直在嘗試。

但是,SQLiteAdministrator和SQLite Datbase Browses均顯示例如1.00:59:59與TimeSpan(24,59,59)插入命令,所以表中的值顯然是OK。

請有人可以告訴我,如何實現1.00:59:59格式的讀取?

非常感謝。

回答

0

此鏈接可能會有所幫助:

http://msdn.microsoft.com/en-us/library/ee372287.aspx

duration.ToString("dd\.hh\:mm\:ss") 

你也應該不需要 '時間(s)爲s' 在你的SELECT語句,而不是隻寫:

select s from test 
+0

謝謝,這正是我需要的格式,但仍然存在問題 - 在哪裏或以何種方式使用它?做這樣的事情: 'dataGridView1.Columns [「s」]。DefaultCellStyle.Format = @「dd \ .hh \:mm \:ss」;' 什麼都不做...... – jindrich