0

I am trying to build an SQL query to compare date in my txtDate box to one in access database for my database search-page. I'm clueless as to which is the best method to do this. Obviously just comparing the textbox value doesn't work. This is my current if-function to check it:

else if((DropDownList1.SelectedValue == "") && (txtDate.Text != ""))
			{
				strSQL = "SELECT * FROM [" + DropDownList2.SelectedValue + "] WHERE DATE_START = " + txtDate.Text;
			}

And is there any better way to build different kind of searches other than lots of if and elseif functions in a row, like i have done?

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by tuomari
0

Hmm seems that i was missing "'" around the date, now it works i think. How about my other question, optimizing my search so it wouldnt be lots of if's in a row?

0
else if((DropDownList1.SelectedValue == "") && (txtDate.Text != ""))
{
strSQL = "SELECT * FROM [" + DropDownList2.SelectedValue + "] WHERE DATE_START =#" + txtDate.Text + "#";
}
0

My search still isn't working properly... it shows every result in the database even though i have WHERE definition in the string.

DateTime dtDate = Convert.ToDateTime(txtDate.Text);

strSQL = "SELECT * FROM [" + DropDownList2.SelectedValue + "] WHERE DATE_START >= '" + dtDate.Year + "-" + dtDate.Month + "-" + dtDate.Day + "'";

How should i modify my SQL query so that i can get only dates from the access database that has a "newer" date than the one in my txtbox (which i converted to datetime)?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.