473,654 Members | 3,040 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Version comparison for update method

HaLo2FrEeEk
404 Contributor
I've written an update method for one of my programs and for the most part it works well, but there is a slight issue. The way I have it check for updates is to simply download an XML file from my server and check the major, minor, and revision numbers in the file against those of the application. So if my application version is 2.2.1 and the XML file says 2.2.2, then the program would know an update was available. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. if (updateMajor > major || updateMinor > minor || updateRevision > revision)
  2. {
  3.     // Update stuff
  4. }
The problem is, it doesn't always work how it's supposed to. For example, if I have an application version 2.2.2 and the update file says 2.1.2, it will prompt me to update since the minor version number in the XML is smaller than te application's version.

My question: what would be a better way to check for this? I keep going back to thinking nested if statements, something like:

Expand|Select|Wrap|Line Numbers
  1. if (updateMajor >= major)
  2. {
  3.     if (updateMinor >= minor)
  4.     {
  5.         if (updateRevision > revision)
  6.         {
  7.             // Update stuff here...
  8.         }
  9.     }
  10. }
But something seems wron with that. Maybe it's just me though, does this look right to you guys, or is there a better way?

And for the record, I'm discarding the *actual* revision number in a standard Assembly Version, and substituting it with the Build number. I do this just because I think 4-digit versions are ugly. Personal preference.
Nov 6 '10 #1
1 2483
GaryTexmo
1,501 Recognized Expert Top Contributor
The nested if statement is the same as changing all the || to && in your original one, and it would mean that 2.2.2 -> 2.2.3 wouldn't update.

I wonder, could you just combine them all into a single number? Lets say you're reserving 3 digits for major and minor, then 4 digits for the revision... I think that's fairly common.

You can just shift them into a double and compare the numbers.

Expand|Select|Wrap|Line Numbers
  1. double verNum = major * Path.Pow(10.0, 3.0) + minor + rev / Math.Pow(10.0, 4.0);
So for your cases of 2.2.2 and 2.2.1, they should come out to 2002.0002 and 2002.0001 respectively. You can easily perform a comparison on those.

Does that work?
Nov 6 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2554
by: jiangyh | last post by:
hey guys: I use SqlDataAdapt.update method to update database that appearance an error looks like following. Update unable to find TableMapping or DataTable 'Table'. Here is My Code //----------------------------------------------------------
0
959
by: | last post by:
Hello Guys, I used the Find method of the Rows class to get a single row from the DataSet which is filled using a DataAdapter. Now my question is, I have a column which is "ADDRESS". I am trying to change the address column of that row and update the DataSet using Adapter's Update method. foundRow = something;
1
2311
by: mivey4 | last post by:
Okay, The problem is that I have an Access Database that has the following fields: EmpID - Autonumber (PrimaryKey) AccountID - Text IssueReported - Memo DateOpened - Date/Time TimeOpened - Date/Time
0
1747
by: Erik | last post by:
Why isn't my update method getting called? Pasted below is an aspx from a 1.1 application I'm working on. It has two textboxes and a button for inserting data into the database, and a datagrid for editing and deleting data. When a user clicks on the "Edit" button in the datagrid, Edit() method is called and the appropriate row is changed into textboxes. And if user clicks on the "Update" button, the Update() method is fired. But if...
2
2091
by: xyzbindu | last post by:
hello, iam a student & need help regarding UPDATE method of dataadapter when i update the database using dataadpter.update(dataset,tablename) i get the following error an unhandled exception of type system.invalidoperation exception occured in system.data.dll additional information:update requires a valid updatecommand when passed datarow collection with modified rows please ur help is appreciated.
1
1934
by: santhoshcz | last post by:
Hi i am using a dataset to update a table in database. I am using a loop to insert multiple records in the dataset.The dataset gets updated perfectly in the dataset.But when i call the adapter.update method i.e. adap.Update(ds,"table") only the last record gets added n times.... I don know wats happening there.. Can anyone help me??? Thanks
1
10143
by: sphinney | last post by:
All, I have a ADODB.Recordset in my Access 2002 project. I've been able to successfully add fields to the record set. According the the MS Access help files, I now must update the recordset to get the field additions to "stick." For example, the code below shows how the Access help files say to append fields to a ADO recordset. dim ADO_RS as ADODB.Recordset set ADO_RS = (some other ADODB recordset) ADO_RS.Close...
1
5409
by: Max2006 | last post by:
Hi, I am truing to find a pattern for my Business Logic Layer to be able to work fine win ObjectDataSource's Update method. The challenge is ObjectDataSource is not able to work with an update method that accepts a strongly typed data table as parameters. We have to have an update method with all data table's columns as its parameter. Like what we have here: http://asp.net/learn/data-access/tutorial-16-cs.aspx
2
2626
by: Aamir Ghanchi | last post by:
Hi, Why does the Update method of an ObjectDataSource class requires parameters for each of the Bind input controls of a FormView? I have a class (say MyObjectDataSource) that is being used as an ObjectDataSource for a FormView control. MyObjectDataSource has public properties that correspond to db table columns and are also used to < %# Bind("")%Input controls in the formview declaratively. There is an Update method in...
1
2420
Fary4u
by: Fary4u | last post by:
Hi, I'm attempting to update a record via the recordset.update method, However, the recordset object is defined and accesses the correct record that I want to update, as I can retrieve field values from the record. The open string for the recordset that I'm using should allow changes: ors.open "Select * from products where productname='"&request("txtname")&"'",ocon1,Adopendynamic,Adlockoptimistic
0
8375
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
8815
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...
0
8707
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8482
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
7306
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
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
5622
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();...
1
2714
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
2
1593
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.