473,587 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to know which rows are modified in a database

Hi,
I want to know if I have changed a few records in my database using update /
insert / delete methods, how can i later know which rows have been changed
or modified ?
I know the ExecuteNonQuery method which can give me the "number" of modified
rows, but which rows are changed how do I know ?
Any ideas ?

Jul 21 '05 #1
4 1822
On a datarow object you have the RowState property which will tell you
whether or not a row has been modified/added/deleted/etc..

If you want to see if a database has been modfied itself since you last
touched it, look into using Concurrency.

-CJ

"Support" <an*******@disc ussions.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,
I want to know if I have changed a few records in my database using update / insert / delete methods, how can i later know which rows have been changed
or modified ?
I know the ExecuteNonQuery method which can give me the "number" of modified rows, but which rows are changed how do I know ?
Any ideas ?

Jul 21 '05 #2
Hi,

In addition to what CJ said about each DataRow having a RowState, you could
also create a DataFilter object and use that to filter the rows. Something
like this:

Dim myDataView as New DataView(myData Table)
myDataView.RowS tateFilter = DataViewRowStat e.ModifiedCurre nt

If you'd rather have the original values of the changed rows, substitute
"ModifiedCurren t" with "ModifiedOrigin al".

HTH,
Derrick

"Support" <an*******@disc ussions.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,
I want to know if I have changed a few records in my database using update / insert / delete methods, how can i later know which rows have been changed
or modified ?
I know the ExecuteNonQuery method which can give me the "number" of modified rows, but which rows are changed how do I know ?
Any ideas ?

Jul 21 '05 #3
Not as easy as it sounds. If you are passing in statements like:
Update Orders Set TotalTax = 1000 Where ShippingState = 'TX'

And then you want to know what rows you changed... that's definitely not
simple.

A couple of ideas:
1) Triggers: this is probably the most common. Triggers in SQL Server get a
rowset that contains the changed rows. You can add a new column to your
table, and then you can add code into an Insert or Update trigger to change
the value of that column to indicate a particular value... then you can
readily look for the list of rows with that value. (Getting that value into
the trigger is hard, but this requires few changes to your existing
queries).

2) Similar to #1 above, but do this in the SQL stmt itself... Add a
transactionId column to your table, then change your SQL queries to
something like this:
Guid TransId = Guid.NewGuid();
String sSql;

sSql = "Update Orders Set TotalTax = 1000, TransactionId = " +
TransId.ToStrin g() + " Where ShippingState = 'TX'";

(note: I prefer stored procs... I used a SQL stmt to demonstrate the
concept, not to encourage this practice. no flames please).

3) Prequeries:
In a stored procedure, open a transaction. Then query the database to
return the primary key of every row that matches your update query. Then
perform the update and commit. In the application code, capture the list of
primary keys. You now have a rowset that you can use to determine what rows
were updated.

4) Transaction tables:
Create a transaction table of the sort:
TransactionId (PK) (either UniqueIdentifie r or int Identity(1,1))
RowPrimaryKey (FK)
SelectDate (datetime)

Then, when you want to update rows in the table of interest, call a
procedure that adds rows to your transaction table for the primary key of
each row that matches your particular criteria:
Insert TransTable (TransactionId, RowPrimaryKey, SelectDate) Select
@TransId, OrderId, getdate() from Orders where ShippingState = 'TX'

As you can see, I prefer Guids over Identity columns... I've spent way too
much time trying to fix a poor design when doing a merge.
If, on the other hand, you use Identity columns, the db can create the
value for you, but you will have to have the sp return the @@Identity
variable.

Anyway, the middleware now has a transaction id. Use that to update your
rows.
Update Orders Set TotalTax = 1000 where OrderId in (Select RowPrimaryKey
from TransTable Where TransactionId = @TransId)

This one allows you to create a set of rows that met the criteria at a
particular point in time, and maintain that set over time, regardless of how
the rows themselves change. You can perform many actions on the set, and
use it for auditing and reporting, both before and after you apply the
actual change.

I don't know which of these techniques you may wish to use... Just some
suggestions.

--- Nick

"Support" <an*******@disc ussions.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,
I want to know if I have changed a few records in my database using update / insert / delete methods, how can i later know which rows have been changed
or modified ?
I know the ExecuteNonQuery method which can give me the "number" of modified rows, but which rows are changed how do I know ?
Any ideas ?

Jul 21 '05 #4
>
sSql = "Update Orders Set TotalTax = 1000, TransactionId = " +
TransId.ToStrin g() + " Where ShippingState = 'TX'";

(note: I prefer stored procs... I used a SQL stmt to demonstrate the
concept, not to encourage this practice. no flames please).

RABBLE RABBLE RABBLE! Stored Procs only! RABBLE RABBLE RABBLE!

=)

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1463
by: Kevin Gale | last post by:
Hi. I need to replicate data (approx. 10,000 records) from a mySQL database into a different (non mySQl) database automatically on a regular basis. I have no control over the mySQL server (apart from allowing ODBC access) so I cannot modify any tables or enable replication etc... My initial thoughts on how to do this are: 1. Execute a...
1
1650
by: Yama | last post by:
Hi, I am really confused. I have created a strong typed dataset for Northwind database Customer table. Now I am loading it with a stream of XML (ADO style) with the following: Customers _cust = new Customers(); XmlTextReader xmlReader = new XmlTextReader(stream); stream.Position = 0;
6
9378
by: Fan Ruo Xin | last post by:
I try to copy a table from production system (DB2 UDB EEE V7.2 + fixpak5) to the testing system (DB2 UDB V8.1 + fixpak4a). I moved the data from productions system by using the following steps: On production system: $ db2 "export to xxxxx.del of del select * from xxxxxx" On testing system: I use db2 utility autoload, because I use the...
4
1054
by: Support | last post by:
Hi, I want to know if I have changed a few records in my database using update / insert / delete methods, how can i later know which rows have been changed or modified ? I know the ExecuteNonQuery method which can give me the "number" of modified rows, but which rows are changed how do I know ? Any ideas ?
3
1449
by: Nathan | last post by:
Hi, When I update my database, I call the updates like this (in order to submit hierarchial changes properly): daAdapter.Update(tblMyTable.Select("", "", DataViewRowState.Added)) daAdapter.Update(tblMyTable.Select("", "", DataViewRowState.ModifiedCurrent)) daAdapter.Update(tblMyTable.Select("", "", DataViewRowState.Deleted))
1
1653
by: Jeff Silverman | last post by:
I have a PHP program that almost works. I'm running it from the command line and simulating a form using a GET method. That part is working, but I get spurious records with all of the fields concatenated into a single field. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;...
7
4544
by: jb1 | last post by:
Hello All, I am trying to create a DTS package. I have two tables tbl_A and tbl_B with similar data/rows but no primary keys. tbl_A is master. I would like this package to query tbl_A and tbl_B and find 1)all rows in tbl_A that are different in tbl_B, 2)all rows in tbl_A that are not present in tbl_B and
14
6982
by: Yas | last post by:
Hello, I have 2 tables, Table1 and Table2. I have copied all data from Table1 to Table2. However Table1 is dynamic it has new rows added and some old rows modified everyday or every other day... How can I continue to keep Table2 up to date without always having to copy everything from Table1? Basically from now on I would only like to...
2
7567
by: jogisarge | last post by:
Hi @all, ich have a datatable added to a dataset. the dataset is binded to a datagridview. How can i get all modified rows from the dataset ? I have to check all the modified rows in a loop.
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.