I have a dataset with 2 'SHORT TIME' format, but these 2 fields will show as a 'DATE' format in DataGrid. How to solve this problem? Anyone out there?:confused:
Printable View
I have a dataset with 2 'SHORT TIME' format, but these 2 fields will show as a 'DATE' format in DataGrid. How to solve this problem? Anyone out there?:confused:
Hi,
Are you loading the datagrid with data from the database ?
YES, correct!Quote:
Originally posted by lianwk
Hi,
Are you loading the datagrid with data from the database ?
datagrid.datasource = dataset
and dataset has 2 'short time' fields, but display 'DATE' format in datagrid.
First method
Direct format the fields from the query level.
Second Methods.
If you have added a table style to your datagrid (so individual column styles have been generated), then you can use code such as this to set the Format property of the particular column style.
[VB.NET]
Dim dgtbc as DataGridTextBoxColumn
dgtbc = CType(dataGrid1.TableStyles(0).GridColumnStyles(3), DataGridTextBoxColumn)
If Not dgtbc is Nothing Then
dgtbc.Format = "g" ' or "u" or whatever format you want to see
End If
I don't have add a table style, and there is an error shown that "out of range", May i know what does GridColumnStyles(3) means?Quote:
Originally posted by lianwk
First method
Direct format the fields from the query level.
Second Methods.
If you have added a table style to your datagrid (so individual column styles have been generated), then you can use code such as this to set the Format property of the particular column style.
[VB.NET]
Dim dgtbc as DataGridTextBoxColumn
dgtbc = CType(dataGrid1.TableStyles(0).GridColumnStyles(3), DataGridTextBoxColumn)
If Not dgtbc is Nothing Then
dgtbc.Format = "g" ' or "u" or whatever format you want to see
End If
I'm just using a simple datagrid with setting the datasource to a dataset.
The "3" in the code mean the column 4. and is adjustable.
Anyway if want some source code referecne, you can goto:
http://www.syncfusion.com/FAQ/WinFor...c44c.asp#q974q
There got lots of solution for datagrid and the sample code in C# and VB.NET
I recommended you use the first method because when you change the column count then you have to change the code also.
You can use CAST or CONVERT in Microsoft SQL database.
I have a field is Date/Time format, example data = 8/21/2003 2:02:00. I want only retrieve the Time format which will display only 2:02:00. How to do that???Quote:
Originally posted by lianwk
The "3" in the code mean the column 4. and is adjustable.
Anyway if want some source code referecne, you can goto:
http://www.syncfusion.com/FAQ/WinFor...c44c.asp#q974q
There got lots of solution for datagrid and the sample code in C# and VB.NET
I recommended you use the first method because when you change the column count then you have to change the code also.
You can use CAST or CONVERT in Microsoft SQL database.
I thought i can use Time(datetimefield1) instead of using only 'datetimefield1' in SQL statement.
So...as you mentioned using the first method, can you please explain more clearly?
Ok...
Since you don't mention about what database you are using. So i assume you are using Microsoft SQL Server 2000.
Assume the field named "myDateTime"
Assume the table named "MyTable"
the query is like below:
SELECT CONVERT(VARCHAR(15), myDateTime, 108) FROM myTable
where the VARCHAR(15) is the output you need after convertion.
for other convertion please refer to the Microsoft SQL Server ebook which comes together with the installation CD. (part of the installation items)
As i tested over here, it works. If you need futher assistance .... post... post ... and post.
When creating a database you can choose to only have the time.
Or you can edit the datagrid.
Not sure on how to edit the datagrid without using a datetimepickler but with it.
Dim test As String
DateTimePickler1.Value = datagrid.item(row,column)
test = DateTimePickler1.Value.ToShortTimeString
MsgBox(test)
You can have datagrid.item(row,column) instead of test
Think that should give you only the time in the datagrid
OK...sorry, my database is Microsoft access database...can it be the same command?Quote:
Originally posted by lianwk
Ok...
Since you don't mention about what database you are using. So i assume you are using Microsoft SQL Server 2000.
Assume the field named "myDateTime"
Assume the table named "MyTable"
the query is like below:
SELECT CONVERT(VARCHAR(15), myDateTime, 108) FROM myTable
where the VARCHAR(15) is the output you need after convertion.
for other convertion please refer to the Microsoft SQL Server ebook which comes together with the installation CD. (part of the installation items)
As i tested over here, it works. If you need futher assistance .... post... post ... and post.
Hi,
Then study the query below:
SELECT FORMAT(myColumn, "hh:mm:ss") FROM myTable;
where
myColumn = the datetime column
myTable = table in the access database.
* This is only example, for the correct format. Please refer to the Microsoft Access Format Setting... Enjoy :) :)