Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server
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 3-Jan-13 8:02am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
selva_1990 at 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...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
CREATE TABLE [dbo].[balance_history](
    [ref_id] [int] NOT NULL,
    [balance] [money] NOT NULL,
    [total] [money] NOT NULL,
    [timestamp] [datetime] NOT NULL
) ON [PRIMARY]
 
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]
 
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
  Permalink  
v2
Comments
selva_1990 at 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 at 3-Jan-13 13:18pm
   
if i update 3 times then 3 different times need to stored and soon
Zoltán Zörgő at 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ő at 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 at 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)
selva_1990 at 3-Jan-13 13:30pm
   
ya of course i need to store history
Zoltán Zörgő at 3-Jan-13 15:58pm
   
See update
selva_1990 at 3-Jan-13 21:34pm
   
thank u very much bro i got an solution

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

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100