473,698 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compare 2 datasets?

I have a simple project that requires I take a set of data from an Excel
spreadsheet, compare it to a table in SQL Server (where column names match),
and if there are changes in the Excel sheet, update the SQL Server table
with said changes.

The datasets are about 2000 rows. My thinking is performing a check row by
row is inefficient, so I thought about how I could compare the two as
datasets and resolve differences. The SQL Server table has a primary key
column, but is otherwise identical to the spreadsheet.

How can I do a simple, efficient comparison?
Nov 16 '05 #1
2 9945
Fill a dataset using Excel as a Datasource (excelDataSet). No, configure a
SqlDataAdapter and set the Optimistic Concurrency Property to false in the
wizard (it's on the second to last tab if I remember correctly, it's a
button in the bottom left hand corner that says "Advanced" or something like
that. You can fire updates against it from there. However, your rowstates
will be modified so you'll need to walk the table. This isn't the most
efficient thing in the world, but that's the way the adapter fires updates.

however, if you are sure that you want to SqlServer table to match the
ExcelSheet, why not delete the rows from the SqlServer, do the same thign
with the excel sheet mentioned above except don't worry abou tthe
concurrency option. Instead, set the acceptchangesdu ringfill property to
false, then just call update.
http://www.knowdotnet.com/articles/datasetmerge.html
--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"codejockey " <cj@hotmail.com > wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a simple project that requires I take a set of data from an Excel
spreadsheet, compare it to a table in SQL Server (where column names match), and if there are changes in the Excel sheet, update the SQL Server table
with said changes.

The datasets are about 2000 rows. My thinking is performing a check row by
row is inefficient, so I thought about how I could compare the two as
datasets and resolve differences. The SQL Server table has a primary key
column, but is otherwise identical to the spreadsheet.

How can I do a simple, efficient comparison?

Nov 16 '05 #2
William:

Thanks for the reply. I havent been able to get the sample to work.

I notice the cursor cycling through the Excel records, but the SQL table
always shows up empty. Notice anything wrong here?

private void BeginImport()

{

string xlConn;

xlConn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" +
Server.MapPath( MakeDateFileNam e()) + ";Extended Properties=Exce l 8.0;";

SqlConnection objConn = new
SqlConnection(S ystem.Configura tion.Configurat ionSettings.App Settings.Get("d b
Conn").ToString ());

objConn.Open();

SqlTransaction objTrans = objConn.BeginTr ansaction();

try

{

OleDbDataAdapte r objOLEDA = new OleDbDataAdapte r("my select statement FROM
[Sheet1$]", xlConn);

objOLEDA.Accept ChangesDuringFi ll = false;

DataSet xlDataSet = new DataSet();

// we now have our Excel source data.

objOLEDA.Fill(x lDataSet, "xlData");

SqlDataAdapter objSQLDA = new SqlDataAdapter( );

objSQLDA.Select Command = new SqlCommand();

objSQLDA.Select Command.Transac tion = objTrans;

objSQLDA.Select Command.Command Text = "my select statement identical to
Excels FROM tblDealerCustom ers";

objSQLDA.Select Command.Connect ion = objConn;

SqlCommandBuild er objCB = new SqlCommandBuild er(objSQLDA);

objSQLDA.Accept ChangesDuringFi ll = false;

objSQLDA.Update (xlDataSet, "xlData");
}

catch (Exception ex)

{

objTrans.Rollba ck();

PrintError(ex);

}

finally

{

objConn.Close() ;
}


}

"William Ryan eMVP" <do********@com cast.nospam.net > wrote in message
news:u2******** ******@tk2msftn gp13.phx.gbl...
Fill a dataset using Excel as a Datasource (excelDataSet). No, configure a SqlDataAdapter and set the Optimistic Concurrency Property to false in the
wizard (it's on the second to last tab if I remember correctly, it's a
button in the bottom left hand corner that says "Advanced" or something like that. You can fire updates against it from there. However, your rowstates will be modified so you'll need to walk the table. This isn't the most
efficient thing in the world, but that's the way the adapter fires updates.
however, if you are sure that you want to SqlServer table to match the
ExcelSheet, why not delete the rows from the SqlServer, do the same thign
with the excel sheet mentioned above except don't worry abou tthe
concurrency option. Instead, set the acceptchangesdu ringfill property to
false, then just call update.
http://www.knowdotnet.com/articles/datasetmerge.html
--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"codejockey " <cj@hotmail.com > wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a simple project that requires I take a set of data from an Excel
spreadsheet, compare it to a table in SQL Server (where column names

match),
and if there are changes in the Excel sheet, update the SQL Server table
with said changes.

The datasets are about 2000 rows. My thinking is performing a check row by row is inefficient, so I thought about how I could compare the two as
datasets and resolve differences. The SQL Server table has a primary key
column, but is otherwise identical to the spreadsheet.

How can I do a simple, efficient comparison?


Nov 16 '05 #3

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

Similar topics

0
1577
by: codejockey | last post by:
Please forgive the repost, but I'm trying to avoid the hack I want to implement since I cant get this sample to work. Can anyone help? *********************** William: Thanks for the reply. I havent been able to get the sample to work. I notice the cursor cycling through the Excel records, but the SQL table always shows up empty. Notice anything wrong here?
2
7568
by: gibster | last post by:
Hi I'm looking for some help comparing 2 datasets, each dataset has 2 datatables; the first table's rows consist of text status (1 or 0) GUID
1
1881
by: Mark | last post by:
by m.r.davies I have 2 tables on seperate Db's (and servers) I want to use a datareader on the first table to pick the booking ref, and then use that booking ref to query the 2nd DB when i have the correct row in the 2nd DB I want to compare each field in the 2 tables to see if they match Every time i try and think how i end up with a while loop for the reader on table1 and a while loop for the reader on table 2 any ideas how i'm going...
4
1990
by: Justin Emlay | last post by:
I have two lists. These can be in either table form or array. That is, my data is in a dataset which I can move to an array if need be. ListA is a master list and it contains all items. ListB contains the same items but not necessarily all the items. I need to know which items are missing. I remember messing with a compare array function but now I can't seem to find it anywhere. Ideas? I would rather NOT loop through each item in...
0
1185
by: Frank | last post by:
Hello, Developing an app where the user fills out a sometimes quite lengthy form of chkboxes, txtboxes, radbtns, etc. User responses are saved to a mySql db, which the user can later edit. When the user chooses to edit, I pull the responses from the db, toss them in a dataset, check the checks, fill the txtboxes, etc.,etc. The user then adds, deletes, or changes entries as needed and clicks the Save Changes button. Here is where the fun...
0
1723
by: austenr | last post by:
I need to compare data sets that have been updated with newer versions. Is there a way to compare the old data set to the new one and determine what tables differ? The environment is DB2. Thanks for your help.
6
1836
by: Al | last post by:
I'd like to know if there were any changes in the DataSet which was populated by reading XML file. 6 DataTables with data or just structure with no data inside of it. I think about this scenario: I create 2 datasets and populate both from the same XML file. Then the first one is used as DataSource for many controls and the second one is untouched. If there were some changes in the first one, I'd like to know it and would like to compare...
3
2164
by: sonymathur | last post by:
I'm using two datasets DS1 & DS2 (both hold data with same schema) in VB.Net 1.1 DS1 is main datasets and DS2 is like subset to DS1.Now how should i remove datarows from DS1 that are like in DS2. Thanks In Advance. Sonymathur.
12
3592
by: BillE | last post by:
I'm trying to decide if it is better to use typed datasets or business objects, so I would appreciate any thoughts from someone with more experience. When I use a business object to populate a gridview, for example, I loop through a datareader, populating an array list with instances of a custom class in the middle tier, and then send the array list up to the presentation layer and bind the gridview to it. If I use a typed dataset, I...
0
8672
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8600
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1998
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.