Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi experts

i have an access database called "trend" and there is a table with tow field to store current date and time.
i have a timer control in the form and i want to store current date and time every 10 sec .
datetextbox and timetextbox are binded to my database :
so i did as below :
C#
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.TemplogTableAdapter.Fill(Me.TrendDataSet.templog)
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Me.TemplogBindingSource.AddNew()
        DateTextBox.Text = DateString
        TimeTextBox.Text = TimeString
        Me.Validate()
        Me.TemplogBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.TrendDataSet)
    End Sub

in the form all thing is correct at runtime but data does'nt save in database.
Posted
Updated 17-Jul-13 20:05pm
v2
Comments
Aydin Homay 18-Jul-13 2:28am    
Hi could you tell me why you don`t used UpdateCommand in TableAdapterManager ? and please tell me what is the TemplogBindingSource? and why you don`t used WCF ? at the finally please look at this question answers http://www.codeproject.com/Questions/289586/Poling-Database-with-Timer
Dr_miti 18-Jul-13 3:10am    
i draged my table in my form so a toolbar with navigation button and save button appeared at top of my form i just simply copy the save button codes in my timer tick.
Maciej Los 18-Jul-13 3:18am    
Why do you want to use timer?
Have you tried to debug program?
Dr_miti 18-Jul-13 3:29am    
it is a part of my application not all of that i need to take current date and time every 10 sec.
i added datagridview and i see that new record and the correct data but after stop and restarting my app there is nothing in database .even when i click on save button on navigation control.

1 solution

Hi
Please trace your timer event and be sure generated query(Sql Insert) is a valid you can test it by your dbms(sql server or access or ...) query designer as a simple way:

1- trace timer event
2- cache generated query at here
3- copy/past query from DBMS query designer
4- run the query in DBMS mode (directly on database)

If everything is ok so you have a problem in data access layer ;) please follow of this link and used ADO.net native objects for implementation your data access layer.

Polling Database with Timer[^]
Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]

Best Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900