Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 3rd, 2005, 12:29 AM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to slyverson
Default datagrid view date format

I am creating a datagridview object from a query I pass into OleDB.

My code generates the table just fine, but my columns that have date time values display them with the long date and time format, rather then how i want them to display. (I want the short time format 08:00 AM)

Private Sub CallEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim mcn As String
  Dim ad As OleDbDataAdapter
  Dim ds As DataSet
  Dim cm As OleDbCommand

  mcn = "Provider=Microsoft.Jet.OLEdb.4.0;Data Source=C:\Calls.mdb"
  Dim myConnection As New OleDbConnection(mcn)

  cm = New OleDbCommand("SELECT Location,Program,CallStartTime,CallEndTime,SecondC all FROM Calls WHERE Analyst = " & txtvalue.Text, myConnection)

  ad = New OleDbDataAdapter(cm)
  ds = New DataSet

 Try
    ad.Fill(ds)
    DataGrid1.DataSource = ds.Tables(0)
 Catch ex As Exception
    MessageBox.Show(ex.Message)
 End Try

    End Sub

If anyone can tell me how to make my two date columns containing the short dates, please let me know.



Slyverson
slyverson@yahoo.com
 
Old December 3rd, 2005, 01:04 AM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to slyverson
Default

I found that I could add the formatting to the select statement. Now, my only problem is instead of having the names of the columns I want in the datagrid, they come through as Exp2344 or whatever. Anyone know of a way to fix that?

Slyverson
slyverson@yahoo.com
 
Old December 3rd, 2005, 10:52 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to alias your query fields:

SELECT field1 AS NewColumnName, field2 AS AnotherColumnName FROM...

It's not clear from your post what type of control you are using (win datagrid, web datagrid). I assume because you are not calling .DataBind() you are in a win form. Either way, you should be able to specify the column formatting in the control. I'm not familiar with the win form datagrid control so I can't offer more than this.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
date format differs, need to force format somehow patricolsson ASP.NET 2.0 Basics 1 December 3rd, 2009 12:53 AM
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
How to give Date format while entering date Subuana Beginning VB 6 4 March 17th, 2006 07:25 AM
View Text in HTML Format echovue Access 4 February 13th, 2006 02:00 PM
date format differs, need to force format somehow patricolsson HTML Code Clinic 2 January 12th, 2006 05:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.