Problem with saving current time

drew4663

Well-known member
Joined
May 3, 2007
Messages
62
Programming Experience
1-3
I am using sql server and I am trying to have a timestamp of when a workorder was issued. When the form is complete I want to hit submit and the time be saved in the database. So far I have a textbox linked to my database called "issuedtextbox". Here is the code I have

IssuedTextBox.Text = TimeString

What this does is just constantly run the time and when I click save the form saves. When I re-open the dataform the time shows the current time again.

Also, I am going to be using a label so the code will actually be

issuedlbl2.text = timestring


In conclusion my problem is that I cannot get a saved timestamp upon completion of a workorder inside sql server database. Thanks.
 
You haven't mentioned what TimeString is. Is it a function you call, a variable or what?

Why don't you add the code to your save function?

So you would bind your label or textbox to that field in your database, then when you click the save button have

VB.NET:
Public Sub btnSave_click (.........) Handles me.btnSave.Click

me.issuedlbl2.text = 'save the time as of NOW

me.tableadapter.update(me.dataset.datatable)

End Sub

so set the time the form is saved and save it to the database (obviously you need to replace the me.tableadapter.update(me.dataset.datatable) line with your correct values).

then when you open the form, because the label is bound to the database, you will see the time the form was saved, not the time the form is opened.
 
You could use a trigger (if your DB supports it) to update a "DateTimeUpdated" column with a function such as GetDate() for the column value.
 
That field is already tied to the database and should be updating and saving the time. As far as timestring is concerned all I did was type it in because I had read in another forum that is how you display the current time. All I did was type it in and bam it worked. More later...got to get back to work.
 
I am using sql server and I am trying to have a timestamp of when a workorder was issued. When the form is complete I want to hit submit and the time be saved in the database. So far I have a textbox linked to my database called "issuedtextbox". Here is the code I have

IssuedTextBox.Text = TimeString

What this does is just constantly run the time and when I click save the form saves. When I re-open the dataform the time shows the current time again.

Also, I am going to be using a label so the code will actually be

issuedlbl2.text = timestring


In conclusion my problem is that I cannot get a saved timestamp upon completion of a workorder inside sql server database. Thanks.

Your entire post feels like youre making the most basic error possible when it comes to databases and dates; youre trying to turn a string into a date, without being explicit about the format. Instead you would be wiser to use a parameterised query with one of the parameters set to type date, not string-and-hope-the-db-can-guess-what-date-it-is

for example, the date:
12/11/10 09:08:07

You tell me, what date this is.. Write it out in words, and I'll let you know if youre right ;)


Actually, the most sensible option is let the database supply the date:

INSERT INTO workerThing(workerName, clockInTime) VALUES("fred smith", NOW() )
 
@ cjard

Well, I am so sorry that I am making such a basic mistake that you had to take time out of your busy schedule to deal with such an incompetent wannabe programmer. Hopefully with enough trials and many errors I can one day be as fruitful with my programming skills as yourself. I do appreciate your efforts of becoming the hero and reminding me to never end up like you. Be blessed!
 
ROFL. That post made my day. Sorry if my last post to you came across as a bit condescending :)

For more info on related subjects, you can read the PQ link in my signature
 
Back
Top