Hi:
I am new to this forum. If I am not through in my explanation then please let me know.
I need help in figuring out how I can accomplish the following.
I am using VB.net for the front end application, and connecting it to the Access database
In the VB form I have a data grid. I am trying to fill the datasource of the data grid from the access table.
I have an access table (Name: Scheduleitem). It has 6 cols. Out of which there are two Date/Time cols.
Date/Time col #1 is named "Start Time"
Date/Time Col #2 is named "end time"
Entries in "Start time" Col are
9:00 AM
12:00 PM
12:30 PM
1:00 PM
5:30 PM.
In the datagrid I want Time to be displayed. I do not want to convert it to a string because the sorting gets messed up. If you know any other way to prevent the sorting from getting messed up then please let me know.
I am using the following code at this point of time. - Try
-
-
-
myQuery = "SELECT Tb1.StartTime, Tb1.EndTime, Tb2.Rolename FROM ScheduleItem as Tb1, racRoles as Tb2 WHERE ScehduleID=" + mstrScheduleID + " AND PersonID=" + mstrPeronID + " And tb1.RoleID=tb2.RoleId order by Tb1.StartTime ASC"
-
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(myQuery, myConnection)
-
-
Try
-
da.Fill(ds, "Schedule")
-
Finally
-
da.Dispose()
-
End Try
-
Return ds
-
Finally
-
myConnection.Close()
-
myConnection.Dispose()
-
End Try
This code gives me the
12/30/1899 9:00 AM
12/30/1899 12:00 PM
12/30/1899 12:30 PM
12/30/1899 1:00 PM
12/30/1899 5:30 PM
Is there a way so that I display only the time and not the date? The date ( 12/30/1899) is being inserted by the system.
I have tried the techniwue of keeping the cols as text instead of date and time. In this case sorting does not work properly in the datagrid.
Then I tried to keep the cols as date/time and used the format method, the result was a string so sorting did not work.
Then I tried using timeserial(hour (starttime),Min ute(starttime), Second(starttim e)) This also resulted with a date inserted.
Thank for your help in advance.
Ajay Bathija
www.ajaybathija .com
20 7896 MMcCarthy 14,534
Recognized Expert Moderator MVP
Try this ... -
Try
-
-
myQuery = "SELECT Format(Tb1.StartTime, "hh:nn A.M./P.M."), Format(Tb1.EndTime, "hh:nn A.M./P.M."), Tb2.Rolename FROM ScheduleItem as Tb1, racRoles as Tb2 WHERE ScehduleID=" + mstrScheduleID + " AND PersonID=" + mstrPeronID + " And tb1.RoleID=tb2.RoleId order by Tb1.StartTime ASC"
-
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(myQuery, myConnection)
-
-
Try
-
da.Fill(ds, "Schedule")
-
Finally
-
da.Dispose()
-
End Try
-
Return ds
-
Finally
-
myConnection.Close()
-
myConnection.Dispose()
-
End Try
Mary
Mary:
Thanks for the help. I highly appreciate it.
You said:
>>Try this ... - myQuery = "SELECT Format(Tb1.StartTime, "hh:nn A.M./P.M."), Format(Tb1.EndTime, "hh:nn A.M./P.M."), Tb2.Rolename FROM ScheduleItem as Tb1, racRoles as Tb2 WHERE ScehduleID=" + mstrScheduleID + " AND PersonID=" + mstrPeronID + " And tb1.RoleID=tb2.RoleId order by Tb1.StartTime ASC"
First, I hoping that I am not missing anything, the only change you suggested was in "Myquery".
I tried using the code that you provided, but vb.net would not accept it, as it was getting confused in the "s being used.
Hence I tried the following: - myQuery = "SELECT format(Tb1.StartTime," + Chr(34) + "hh:nn AM/PM" + Chr(34) + ") as StartTime, format(Tb1.EndTime," + Chr(34) + "hh:nn AM/PM" + Chr(34) + "), Tb2.Rolename FROM ScheduleItem as Tb1, racRoles as Tb2 WHERE ScehduleID=" + mstrScheduleID + " AND PersonID=" + mstrPeronID + " And tb1.RoleID=tb2.RoleId order by Tb1.StartTime ASC"
The Sorted datagridview result was:
01:00 PM
05:30 PM
09:00 AM
12:00 PM
12:30 PM
Based on the above I am assuming that the query returns a string, which causes a problem in sorting. Is there a way I can solve this sorting problem easily.
I need to make sure that the time displayed in the datagrid is sorted properly.
MMcCarthy 14,534
Recognized Expert Moderator MVP
Single quotes will solve that problem. Try this although it may just put the date back in. - myQuery = "SELECT CDate(Format(Tb1.StartTime,'hh:nn AM/PM')) as StartTime, CDate(Format(Tb1.EndTime,'hh:nn AM/PM')), Tb2.Rolename FROM ScheduleItem as Tb1, racRoles as Tb2 WHERE ScehduleID=" + mstrScheduleID + " AND PersonID=" + mstrPeronID + " And tb1.RoleID=tb2.RoleId order by Tb1.StartTime ASC"
Try this although it may just put the date back in.
Mary, thanks for the Single quote information.
I tried the Cdate technique, it inserted the Date (12/30/1899 9:00 AM)
MMcCarthy 14,534
Recognized Expert Moderator MVP
Mary, thanks for the Single quote information.
I tried the Cdate technique, it inserted the Date (12/30/1899 9:00 AM)
Thought that might happen
MMcCarthy 14,534
Recognized Expert Moderator MVP
Try this ... - myQuery = "SELECT TimeValue(Format(Tb1.StartTime,'hh:nn AM/PM')) as StartTime, TimeValue(Format(Tb1.EndTime,'hh:nn AM/PM')), Tb2.Rolename FROM ScheduleItem as Tb1, racRoles as Tb2 WHERE ScehduleID=" + mstrScheduleID + " AND PersonID=" + mstrPeronID + " And tb1.RoleID=tb2.RoleId order by TimeValue(Format(Tb1.StartTime,'hh:nn AM/PM')) ASC"
Mary
Try this ... - myQuery = "SELECT TimeValue(Format(Tb1.StartTime,'hh:nn AM/PM')) as StartTime, TimeValue(Format(Tb1.EndTime,'hh:nn AM/PM')), Tb2.Rolename FROM ScheduleItem as Tb1, racRoles as Tb2 WHERE ScehduleID=" + mstrScheduleID + " AND PersonID=" + mstrPeronID + " And tb1.RoleID=tb2.RoleId order by TimeValue(Format(Tb1.StartTime,'hh:nn AM/PM')) ASC"
Mary
Same result, the date is being inserted.
Based on the techniques that we have used, my understanding is that Access is not the one adding the date. The vb.net or the ole Adapter is adding the date.
If I use the simple query for just pulling the time directly (wihtout any formating) in access then it returns the time with no date. When I use that query in the vb.net code then Date is inserted.
I can think of the possible solutions but dont know how to implement them.
1. When the date is pulled form the access and stored in the datasource. I change it,that is remove the date section in the data source itself.
2. While displaying it the data gridview, I display on the time section.
Do you think any of the above listed solutions is possible?
OR would you suggest any other method of displaying this information to the users.
Based on the techniques that we have used, my understanding is that Access is not the one adding the date. The vb.net or the ole Adapter is adding the date.
If I use the simple query for just pulling the time directly (wihtout any formating) in access then it returns the time with no date. When I use that query in the vb.net code then Date is inserted.
The above diagonsis seems to be incorrect. http://www.thescripts.com/forum/thread347463.html
It is Access that is causing the problem I guess.
They have used the "format" technique which did not work in my case due to sorting.
Ajay Bathija www.ajaybathija.com NeoPa 32,571
Recognized Expert Moderator MVP
The above diagonsis seems to be incorrect. http://www.thescripts.com/forum/thread347463.html
It is Access that is causing the problem I guess.
They have used the "format" technique which did not work in my case due to sorting.
Ajay Bathija www.ajaybathija.com
Ajay,
From the SQL posted earlier : - "SELECT TimeValue(Format(Tb1.StartTime,'hh:nn AM/PM')) as StartTime, TimeValue(Format(Tb1.EndTime,'hh:nn AM/PM')), Tb2.Rolename " & _
-
"FROM ScheduleItem as Tb1, racRoles as Tb2 " & _
-
"WHERE ScehduleID=" + mstrScheduleID + " AND PersonID=" + mstrPeronID + " And tb1.RoleID=tb2.RoleId " & _
-
"ORDER BY TimeValue(Format(Tb1.StartTime,'hh:nn AM/PM')) ASC"
You will have problems as you are sorting by the formatted time string. You need to go back to sorting by the field itself. You can SELECT whatever you like, but the sorting should be done by the Date/Time field itself for the results you want. - "SELECT Format(Tb1.StartTime,'hh:nn AM/PM') AS StartTime, " & _
-
"Format(Tb1.EndTime,'hh:nn AM/PM') AS EndTime, " & _
-
"Tb2.Rolename " & _
-
"FROM ScheduleItem as Tb1, racRoles as Tb2 " & _
-
"WHERE ScehduleID=" + mstrScheduleID + " AND " & _
-
"PersonID=" + mstrPeronID + " And tb1.RoleID=tb2.RoleId " & _
-
"ORDER BY Tb1.StartTime ASC"
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Brian Coy |
last post by:
I have a database that records a part no, a scrap reason, the cost of
scrapping that item, and the date. I need to porduce a report that
will show up to a weeks worth of data at a time, but I need each dates
scrap amout totaled and each day to be separated on the report. I am
self taught at access and still a beginner, so please be gentle on
your replys.
Thanks for your time in advance...
|
by: Agnes |
last post by:
I know how to display Date only in the textbox . but How about the time ???
Can I put it into two separate textbox , but save in one datafield ?
thanks a lot.
|
by: LurfysMa |
last post by:
I would like to hear opinions on the tradeoffs of putting the tables,
forms, and queries for several related datasets in separate databases
vs one combined database.
I am working on an application that will have a number of "subjects".
The subjects have a number of commonalities, but are not identical. I
am hoping that I will discover that the subjects fall into a few
"types" and a common database structure can be used for each type.
...
|
by: colleen1980 |
last post by:
Hi: Data in my table is in that format. How to i separate date with
time.
11/9/2006 10:10:46 AM
Thank You.
|
by: drurjen |
last post by:
Good morning.
I am importing an XLS file into one of my tables. The fields are:
Date Id Time IO
12/22/2006 2 12:48:45 PM 9
12/22/2006 16 5:40:55 AM 1
12/22/2006 16 12:03:59 PM 2
When I do the import, I get the following:
| |
by: tshad |
last post by:
This was posted before but the message got messed up (all NLs were stripped
out for some reason).
I have 2 labels that hold the name of different images on my .aspx page.
<asp:Label ID="Logo" runat="server"/>
<asp:Label ID="CompanyPicture" runat="server"/>
I have 2 links that open the windows to preview these images. The previewed
images are done on separate html pages that do nothing but display the
|
by: salmobytes |
last post by:
Every img tag (<img src="xxx.jpg">) in the html source represents a
separate
GET roundtrip between client and server, no?
What about background images in css?
I'm starting to see more and more designs--coming from the
graphics design people--that call for ever increasing numbers of
repeat-x or repeat-y sliver-gradients as div backgrounds. Does each
such
background image require a separate GET to the server?
|
by: Yasin |
last post by:
Walt <walt@boatnerd.com.invalidwrote in message news:<3F0C5BA9.DB809458@boatnerd.com.invalid>...
You can use below sql for your result
select * from test;
PERSON_ID DAT TIME CODE
--------- -------- ----- ----------
1 26.04.98 07:00 First one
2 08.07.03 16:00 Second
|
by: dizzydangler |
last post by:
Just a quick question...I'm running an MS Access 2007 db that tracks appointments in a single table. Date and time are entered as separate fields in short date (mm/dd/yyyy) and short time (hh:mm) format. I've been running queries by date alone, which has been working, but there are times when I have to run queries based on times as well. (e.g. return all apointments that occurred after 1:00 PM on 12/15/2009 and before 1:00 PM on 12/22/2009). ...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |