· Field name is = tbToDate there only 1 field and I have code for 2 fields… bcz correct me…
private string CreateWhereStr()
{
string strWhere= "";
string strWhereFromDate = tbFromDate.Text.ToString();
string strWhereEndDate = tbToDate.Text.ToString();
try
{
if (( strWhereFromDate.ToString() != "" ) && (strWhereEndDate.ToString() != "" ))
{
DateTime WhereFromDate = ConvertDate(strWhereFromDate) ;
DateTime WhereEndDate = ConvertDate(tbToDate.Text.ToString()) ;
if (WhereFromDate.Date > WhereEndDate.Date )
{
throw new ArgumentException(" ‘To Date’ must be bigger than ‘From Date’.");
}
else
{
strWhere = strWhere + " AND to_date(EXPIRE_DATE) > to_date('" + strWhereFromDate.ToString() + "','dd/MM/yyyy') AND to_date(EXPIRE_DATE) < to_date('" + strWhereEndDate.ToString()+ "','dd/MM/yyyy')" ;
}
}
else if (( strWhereFromDate.ToString() != "" ) && (strWhereEndDate.ToString() == "" ))
{
strWhere = strWhere + " AND to_date(EXPIRE_DATE) > to_date('" + strWhereFromDate.ToString()+ " ' ,'dd/MM/yyyy')" ;
}
else if (( strWhereFromDate.ToString() == "" ) && (strWhereEndDate.ToString() != "" ))
{
strWhere = strWhere + " AND to_date(EXPIRE_DATE) < to_date ('" + strWhereEndDate.ToString()+ " ' ,'dd/MM/yyyy')" ;
}
}
catch( Exception ex)
{
throw new ArgumentException(ex.Message.ToString()) ;
}
return strWhere ;
}
Jan MontanoPosted Dec 6, 2007, 11:40 PM
What is it that you want to accomplish? And what is the problem with the code you posted? Sorry if I can't understand the problem correctly. I'm quite slow =). Are you doing a windows app? If so, you could use MessageBox.Show() instead to display messages.
I just noticed that you throw exceptions when dates are invalid. It's not best practice to throw exceptions. You could however put the validation in a function which returns a bool value depending if validation is successful or not.
Regards,
Jan