Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using datetimepicker control. if i press UPDATE button, each time while pressing system date and time need to stored in database,(if i press 3 times then 3 times it should store) it should not overwrite...\\is it possible help me out
Posted

Insert three rows into the database.
You don't need to update the column.
Table1
Row1 -> A,B,C,T1
Row2 -> A,B,C,T2
Row3 -> A,D,E,T3


Another neater solution might be to insert an id into a column which points to another table that stores a number of entries for each datetime update.
Table1
Row1 -> A,B,C,id1
Row2 -> A,B,C.id1
Row3 -> A,D,E,id2

Table2
Row1 -> id1, T1
Row2 -> id1, T2
Row3 -> id3, T3
 
Share this answer
 
Comments
selva_1990 3-Jan-13 13:16pm    
these are my fields name,balance,total.... once i inserted data into database, now i need to update the balance field so each time while updating that particular time need to be stored...
Of course it is possible, but your question needs more clarification, like table structure. How to store exactly?
But let's try answering it...
You can achieve this in many ways. Here are two of them:
1) You make an other table that contains a foreign key to whatever you want to link the timestamp and the timestamp. On every Update you not only update what you want, but also insert a row in this table.
2) make an other table that contains a foreign key to whatever you want to link the timestamp and the timestamp. And you create an on update (and probably on insert too) trigger on the primary table that inserts a record in this second table.

To be sure to have the good timestamp, you should let the server give it a value. See: http://msdn.microsoft.com/en-us/library/ms188383.aspx[^]

[Update]
See following sample:
SQL
CREATE TABLE [dbo].[balance_history](
    [ref_id] [int] NOT NULL,
    [balance] [money] NOT NULL,
    [total] [money] NOT NULL,
    [timestamp] [datetime] NOT NULL
) ON [PRIMARY]


SQL
CREATE TABLE [dbo].[balances](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [name] [varchar](50) NOT NULL,
    [balance] [money] NOT NULL,
    [total] [money] NOT NULL,
 CONSTRAINT [PK_balances] PRIMARY KEY CLUSTERED ( [id] ASC )
) ON [PRIMARY]


SQL
CREATE TRIGGER [dbo].[TR_STORE_]
   ON  [dbo].[balances] AFTER UPDATE
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO BALANCE_HISTORY(ref_id, balance, total, [timestamp])
    SELECT id, balance, total, GETDATE()
    FROM DELETED;

END
 
Share this answer
 
v2
Comments
selva_1990 3-Jan-13 13:17pm    
these are my fields name,balance,total.... once i inserted data into database, now i need to update the balance field so each time while updating that particular time need to be stored...
selva_1990 3-Jan-13 13:18pm    
if i update 3 times then 3 different times need to stored and soon
Zoltán Zörgő 3-Jan-13 13:20pm    
Ok. You can not store more than one value in a field. You need a second table.
Zoltán Zörgő 3-Jan-13 13:23pm    
You want to use this as a history, don't you? Than you will probably need to store other fields in the history too, not only the timestamp.
selva_1990 3-Jan-13 13:28pm    
in second table if i am keeping fields as time and balance
if i update first time 11:54 5000
if i go for 2nd update 12:00 4000
if i go for 3rd update 12:30 3000
like this i need and this all for one person(i mean for one record)

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