|
-
Aug 21st, 2003, 10:17 PM
#1
Thread Starter
Lively Member
short time format in datagrid
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?
-
Aug 21st, 2003, 10:20 PM
#2
Lively Member
Hmmm...
Hi,
Are you loading the datagrid with data from the database ?
-
Aug 21st, 2003, 10:24 PM
#3
Thread Starter
Lively Member
Re: Hmmm...
Originally posted by lianwk
Hi,
Are you loading the datagrid with data from the database ?
YES, correct!
datagrid.datasource = dataset
and dataset has 2 'short time' fields, but display 'DATE' format in datagrid.
-
Aug 21st, 2003, 10:29 PM
#4
Lively Member
Two methods.....
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
-
Aug 21st, 2003, 10:40 PM
#5
Thread Starter
Lively Member
Re: Two methods.....
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 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?
I'm just using a simple datagrid with setting the datasource to a dataset.
-
Aug 21st, 2003, 11:08 PM
#6
Lively Member
Sorry... lack of informations.
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.
-
Aug 22nd, 2003, 12:43 AM
#7
Thread Starter
Lively Member
Re: Sorry... lack of informations.
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 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???
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?
-
Aug 22nd, 2003, 02:30 AM
#8
Lively Member
Hmmm...
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.
-
Aug 22nd, 2003, 03:08 AM
#9
Member
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
-
Aug 22nd, 2003, 03:24 AM
#10
Thread Starter
Lively Member
Re: Hmmm...
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.
OK...sorry, my database is Microsoft access database...can it be the same command?
-
Aug 22nd, 2003, 03:56 AM
#11
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|