Hi,

I am working on a project in which i've to identify a textbox value,

The end user may enter a date (dd\mm\yyyy) or may enter a ticket number (alphanumeric:ex:'VD103'),

can anyone tell me how to distinguish the date or string values entered in the textbox so that depending upon that i am able to connect to the database

Kiran.

you can use Datetime.ParseExact

Show me your work to get more.

commented: Nice suggestion. +6

My code looks like this
I've used the datetime.exactparse to distinguish between date and string
but
error is that we cannot use
DateTime.ParseExact(strByDateByTkt, strformat, CultureInfo.InvariantCulture) as a bool type

what should i do

public void btnByDayByTktGo_Click(object sender, EventArgs e)
    {
        objCommon = new HDCommon();
        string strVenName = ddlVenTktLog.SelectedValue.ToString().Trim(),
               strStatus = ddlVenTktStatus.SelectedValue.ToString().Trim(),
               strByDateByTkt = txtVenTktSrchByDayByTkt.Text.ToString().Trim(),
               strformat="dd/mm/yyyy",
               strMode = "C",
               strCheckId="";

     if ((DateTime.ParseExact(strByDateByTkt, strformat, CultureInfo.InvariantCulture)))
        {
                BindGrid(strVenName, strStatus, "", "", strMode,                                
                      objCommon.DateFormat(strByDateByTkt,"MM/DD/YYYY"), "");
        }
        else
        {            
            BindGrid(strVenName, strStatus, "", "", strMode, strByDateByTkt, "");
        }
    }

I have no clue what you are trying to do.

Please use code tagging.
try

if (DateTime.Compare(DateTime.ParseExact(strByDateByTkt, strformat, System.Globalization.CultureInfo("en-US")), new DateTime(2010, 03, 15)) == 0))
{

==0 means the date is equal
< 0 means the right date is less than the left date
> 0 meand the right date is higher than the right date.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.