0

Possible Duplicate:
C#/SQL Database listener help needed

I am writing an application to keep on monitoring the database table from the server machines. If the new entry has been made in to the table, then i have to collect the new details using select query and passed to the final builder as a parameter to start the automation.

Question: How can i find the new entry in database table using c#?

i have no idea about this?

can anyone help me out this?

Community
  • 1
  • 1
Karthi
  • 575
  • 2
  • 10
  • 29
  • Are you considering bulk insertions where identity column could be disabled and then insertion occurs or any other similar case – Shantanu Gupta Sep 23 '12 at 03:24
  • depends if it's just one record or multiple – codingbiz Sep 23 '12 at 04:01
  • @ Shantanu Gupta:- yes. client entered the details to store it in the database. At a time, more number of clients can enter the details and data will be save in database. can we able to find the recently added all datas to process one by one using c#? – Karthi Sep 24 '12 at 04:25

3 Answers3

1

Use an auto-incrementing ID in the table you are inserting data into. Then, you can retrieve the last inserted id in the same query as the insert and thus have a reference to it. the syntax depends on the type of database you are using, but they all have some way of retrieving the last insert id. See the following article of a SQL query to do this:

http://www.devx.com/vb2themax/Tip/18893

Edit: sorry, i think i misread your problem. You are not the one inserting the data? in which case, you still want an auto-incrementing ID so you can select all rows that have an ID > the last id you retrieved. auto-incrementing IDs do not reuse old ids unless you reset the counter manually.

Levi
  • 2,103
  • 14
  • 9
0

Use an extra column InsertedDateTime in table. Then, see table have any InsetedDateTime greater than last used InsertedDateTime. i.e. you can read all row that have InsertedDatatime > last InsertedDateTime

By using this solution, Application does not need knowledge of PrimaryKey type.(Auto Increment or Non Auto Increment).

Hope this may help.

Jignesh Thakker
  • 3,638
  • 2
  • 28
  • 35
0

You can use a table Trigger to execute a stored procedure which would have the automation instructions.

You can get the inserted row and pass the parameters to the Stored Procedure.

Manoj De Mel
  • 927
  • 9
  • 16