First let me start by saying this,
"The code that you will see below is the worst code I have written".
Okay my requirment was to compare the date in the ACCESS database and spit out the results depending on the date. The field in the database was varchar and date was stored as '03-04-2005' (mm-dd-yyyy). Now I needed to fetch all the records of a particular month and year. The barries was the inclusion of the day in the database. The month and year was selected using the dropdownlists.
Here is my ugly code:
string query = @"SELECT * FROM [TableName] WHERE [DateCreated] = ";
string finalQuery = String.Empty;
for(int i=1;i<13;i++)
{
string c = ddlMonth.SelectedItem.Value + "/" + i.ToString() + "/" + ddlYear.SelectedItem.Value;
finalQuery += query + "'"+c+"'" + " " + "UNION" + " ";
}
int b = finalQuery.LastIndexOf("UNION");
string sss = finalQuery.Remove(b,5);
I hate ACCESS database since it has too many limitations like you cannot run multiple queries which you can do in SQL SERVER. So, I had to make a long query string which joins all the queries by using UNION operator.
This is probably the ugliest code I have ever written. What about you ?