I am currently working on a patching system in C# and I have came across a small complication. I am using MySQL to store an archive for my update list. The patching system then detects the version of program, and downloads every patch after that version. Though I just started learning how to use MySQL in C# so i’m not sure how to do, or call a lot of the functions needed. What I want to do is use foreach to call all values in the “version” column/row, then use a while loop to check against current version and new version until they are the same. I just cant seem to figure out how to use the two together and can’t find any references.
using (SqlCon = new MySqlConnection(connString))
{
SqlCon.Open();
string command = "SELECT * FROM version ORDER BY version";
MySqlCommand GetLatestVersion = new MySqlCommand(command, SqlCon);
using (MySqlDataReader DR = GetLatestVersion.ExecuteReader())
{
while (DR.Read())
{
foreach(DataTable i in DR)
{
while(v1 < v2)
{
string LatestVersion = Convert.ToString(DR.GetValue(1));
string WebURL = Convert.ToString(DR.GetValue(2));
update.DownloadProgressChanged += new DownloadProgressChangedEventHandler(download);
update.DownloadFileCompleted += new AsyncCompletedEventHandler(extration);
update.DownloadFileAsync(new Uri(WebURL), tempFilePath + "patch" + Latest_Version + ".zip");
}
}
}
}
}
SqlCon.Close();
I would greatly appreciate any help.
First thing is you don’t need the
SqlCon.Close();at the end. At the end of theusingblock, the object is disposed of (the point of ausingblock).You can modify your select statement to only select versions greater than your program’s current version. This way, any records selected should be processed/downloaded. (I put the version in quotes in the SQL statement below because your code indicates that it’s a string. You’re probably better off specifying this value as numeric for sorting/comparison purposes, though.)