473,785 Members | 2,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB .NET - Entering 'time' as a string into database... But database attaches a date!

8 New Member
Okay, so after adding an Access database as a data source to my project, I decided to change the 'time' field in a particular table from date/time to a string value for various reasons. I made this change in the original database, the copied database in my project's bin\Debug folder and the dataset. The changes were all saved and everything looked fine.

But then when I went to add an actual 'time' string into the database (in the format 12:00 PM), when I checked the value entered in the field for that record in the database, it had today's date attached to it as well (so 31/10/2007 12:00 PM). I checked that I was actually entering a '12:00 PM' string into the field, and that was fine. But for some reason, when it is actually entered in the database, a date is attached... Even though the field is a string in the database as well!

I really have no idea what the deal with this is... Any advice at all is appreciated.
Oct 31 '07 #1
11 3910
r035198x
13,262 MVP
Okay, so after adding an Access database as a data source to my project, I decided to change the 'time' field in a particular table from date/time to a string value for various reasons. I made this change in the original database, the copied database in my project's bin\Debug folder and the dataset. The changes were all saved and everything looked fine.

But then when I went to add an actual 'time' string into the database (in the format 12:00 PM), when I checked the value entered in the field for that record in the database, it had today's date attached to it as well (so 31/10/2007 12:00 PM). I checked that I was actually entering a '12:00 PM' string into the field, and that was fine. But for some reason, when it is actually entered in the database, a date is attached... Even though the field is a string in the database as well!

I really have no idea what the deal with this is... Any advice at all is appreciated.
Any chance that you are going to post the actual code you used?
Oct 31 '07 #2
shweta123
692 Recognized Expert Contributor
Hi,

Please check that if you have put any validations while designing the table
like validations or default value.Because of which it is possible that , it will attach date to the time even if you add only time value.
Oct 31 '07 #3
dheroan
8 New Member
Well the thing is that the program is doing its job fine (and it's pretty difficult to explain briefly). If I check the value right before it goes into the database, it shows that it's a string in the exact format that I want (so 12:00 PM or whatever). But when I open the database to see what values got entered, it shows this time as well as today's date in the 'time' field.

For example, I have a masked text box that accepts a string in the format 00:00 and radio buttons that allow the user to select AM or PM. This value is then entered as a field in the database table 'tblPrivateLess on'.

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'RetrieveAMOrPM() grabs the radio button value.
  3. LessonTime = msktxtLessonTime.Text & " " & RetrieveAMOrPM()
  4.  
  5. 'Adds a whole bunch of other unimportant fields to a table in the database, including LessonTime.
  6. LearnToRideDataSet.tblPrivateLesson.Rows.Add(LessonTime) 'And other fields.
  7.  
  8. Me.Validate()
  9. Me.TblPrivateLessonBindingSource.EndEdit()
  10.                     Me.TblPrivateLessonTableAdapter.Update(Me.LearnToRideDataSet.tblPrivateLesson)
  11.  
  12.  
I thought it must've had something to do with the data source and how I changed the data type of the time field to string... But it doesn't make sense because the field has visibly been changed to a string everywhere that I can see (in the dataset AND database itself). This is driving me nuts!
Oct 31 '07 #4
dheroan
8 New Member
Hi,

Please check that if you have put any validations while designing the table
like validations or default value.Because of which it is possible that , it will attach date to the time even if you add only time value.
I didn't set any validation rules or default values on the field in the database. =(
Oct 31 '07 #5
Plater
7,872 Recognized Expert Expert
Try adding ANOTHER column of type varchar/string and adding that lessontime string a SECOND time to that new column. (So it will try to save the same string into two different columns).
Maybe there will be a different result?
Oct 31 '07 #6
dheroan
8 New Member
Try adding ANOTHER column of type varchar/string and adding that lessontime string a SECOND time to that new column. (So it will try to save the same string into two different columns).
Maybe there will be a different result?
I tried that by adding a new column in the Access table in the database and updating the dataset.xsd file. When I went to add the same string into the new column (using the same method as in the above code example, but with an extra column in the Add() method), nothing appeared in that column when the record was created.

I tried completely deleting the new column and the old column (in both the data source and the dataset). I added a completely new 'time' column in the same position as the old one, with a string data type. Same thing again when I went to add the time in as a string... The record was created successfully, but the 'time' field for that record was blank.

I have no clue what would be causing this.
Nov 1 '07 #7
Plater
7,872 Recognized Expert Expert
Maybe what you are naming the column has a special meaning? Is the column's name "Time"? try naming it like "columnT" or something maybe?
Nov 1 '07 #8
dheroan
8 New Member
Maybe what you are naming the column has a special meaning? Is the column's name "Time"? try naming it like "columnT" or something maybe?
The column's name isn't actually time, I was just using that to make its purpose clearer. It's actually 'LessonStartTim e'.

The only way I can think of to deal with this is to delete the current data source and then re-attach it... But that'll be an enormous pain in the butt. ><
Nov 3 '07 #9
balabaster
797 Recognized Expert Contributor
The column's name isn't actually time, I was just using that to make its purpose clearer. It's actually 'LessonStartTim e'.

The only way I can think of to deal with this is to delete the current data source and then re-attach it... But that'll be an enormous pain in the butt. ><
This usually has to do with the data format of the field in your table. A DateTime is always stored as just that Date & Time. If one or the other is not important you then you can just ignore it at runtime. When you save it in the database it would be stored as 1/1/1800 and the relevant time. The alternative is to make sure the field is actually of string data type and store the time as a time string, maybe in 24 hour - i.e. "1402" (for 2:02pm). Now in .NET we also have cultures where you can use the System.Globaliz ation to force a parse of an exact date or time string using ParseExact to set the format "HH:mm:ss". Hopefully that should point you in the right direction.
Nov 3 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6503
by: Lauren Quantrell | last post by:
I have two columns in a table: StartDate DateTime and StartTime DateTime. The StartDate column holds a value such as 07/16/2004 The StartTime column holds a value such as 3:00:00 PM I want to be able to add them in a stored procedure. When I use StartDate + StartTime I get a date two days earlier than expected. For example, instead of 7/16/2004 3:00:00 PM StartDate + StartTime returns 7/14/2004 3:00:00 PM.
16
10513
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am using C# eg. - String variable "strMyDate" holds the value "1/1/2005 12:00:00 AM" from the database. - I do not care about the time portion, I only want "1/1/2005" for display.
4
5133
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to code using tools-->references. The converted macro included the following statement: DoCmd.OutputTo acQuery, "qselLabelsBloodLog_output", "MicrosoftExcelBiff8(*.xls)", "S:\susan_cheree\lb041129.xls", True, "", 0
1
5420
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the database so I could sort the records by the date at which they were entered. Well now I've deleted some of those records so its of course causing gaps in the records. The record number in Access no longer matches my record number that I...
3
11731
by: Reney | last post by:
I am using Access Database in my program. The column in the table that I am going to use has date/time value with Medium Time selected. (HH:mm). The program is recording a clock in time to this field, which is the time when the entry is made. If you check the database, it shows the correct time in the correct format. But when you are calling it with a dataset and showing with a datagrid, it doesn't show the time value but it always shows...
15
18894
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract the value in timeonly format by using this command Format(now,"HH:mm:ss") But when I insert it into the Sql Server database, it embadded date value with it. the output looks like that "01/01/1900 08:59:00" in that case time is
1
1309
by: Dave | last post by:
I'm working with SQL Server 2005 and VB.Net. I only want to store the date (not the time) in the DateTime field. I have a text field that is bound to a DateTime field in SQL. When I run the program, the field initially comes up blank for new records. I enter a date (like "03/14/06") and save the record. When I retrieve the record and display it again, the field shows "03/14/06 12:00:00 AM". Now, that's annoying (and I would like to not...
3
3316
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
4
6808
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form allows the employee to enter their UserID and select "Login" or "Logout" and then click a submit. When the submit button is clicked, I want the application to dum the NT Userename, UserID, status (Login or Logout) and a date/time stamp into an MS Access...
0
10324
Oralloy
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...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
agi2029
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...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
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();...
0
5380
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.