Pyodbc and Ms access database

Hi,
I am writing a program to get the time stamp from system then save it to Ms access database using pyodbc,I have a time_stopped,Time_started column. When time_stopped is saved in DB for example,for the next signal it goes to next row,and save the time_started. But I want both of them in same row saved ,and then it can go to next row for saving the next time stamp.Thank u all Help me please

This is my code:

‘’’

if serialString == b'1\r\n' :

            try:
                com = """
                   insert into monitoring (line_name,time_stopped,time_started) VALUES ('G1.1', ?, ?)
                   """
                parameter1 = (x.strftime("%H:%M"))
                parameter2 = (x.strftime("%Y/%m/%d"))
                c.execute(com, parameter1,parameter2)
            except:
                print("error")
                con.rollback()
            print("line 1 stops at:")
            print(now.tm_hour,end=":")
            print(now.tm_min)
            print(now.tm_year,end="/")
            print(now.tm_mon,end="/")
            print(now.tm_mday)
            print('............................')

        else:
            try:
                com = """
                   insert into monitoring (line_name,time_stopped,time_started) VALUES ('G1.1', ?, ?)
                   """
                parameter3 = (x.strftime("%H:%M"))
                parameter4 = (x.strftime("%Y/%m/%d"))
                c.execute(com, parameter3,parameter4)
            except:
                print("error")
                con.rollback()
            print("line 1 starts at:")
            print(now.tm_hour, end=":")
            print(now.tm_min)
            print(now.tm_year, end="/")
            print(now.tm_mon, end="/")
            print(now.tm_mday)
            print('............................')

‘’’
This is executed in a infinite while loop.

The basic approach is that you use an insert to record the start_time.
Having done that, obtain the row id of the newly inserted row. Possibly
it has some other uniquely identifying feature.

Then when you get the end time, you use an SQL UPDATE statement instead
of an INSERT, and use a WHERE clause to identify the specific row you
inserted for the start time.

Also, a remark about your try/except:

 try:
     com = """
        insert into monitoring (line_name,time_stopped,time_started) 
        'G1.1', ?, ?)
        """
     parameter1 = (x.strftime("%H:%M"))
     parameter2 = (x.strftime("%Y/%m/%d"))
     c.execute(com, parameter1,parameter2)
 except:
     print("error")
     con.rollback()

This is a “bare” except, and generally discouraged. Exception may be
raise for all sorts of causes, and you really nly want to catch those
you expect. You also discard the reason for the exception. Change the
except part like this:

except Exception as e:
    print("error:", e)
    con.rollback()

At the least this gives you some information about what failed.

Cheers,
Cameron Simpson cs@cskk.id.au