Q:

search by date range from single column in sql

i have a table tblEvent and column EventDate where i store dates corresponding to events.
I want to search events between range of dates which user selects like (ex: 15/3/2015)
i have tried following
public DataTable SearchEventByDate(string FromDate, string ToDate)
        {

            string query = "select tblEvent.*,tblCustomer.Name as 'CustomerName' from tblEvent,tblCustomer where tblEvent.CustomerID=tblCustomer.CustomerID and tblEvent.EventDate between " + FromDate + "And " + ToDate;
            List<SqlParameter> lstParams = new List<SqlParameter>();
            DataTable dt = DBUtility.SelectData(query, lstParams);
            return dt;
        }

this isn't working

A:

I guess you should change your query and add the following parameters with it .. 
public DataTable SearchEventByDate(string FromDate, string ToDate)
        {
                string query = @"

          SELECT tblEvent.*,
                 tblCustomer.Name as 'CustomerName' 

           FROM  tblEvent,tblCustomer 

          WHERE tblEvent.CustomerID=tblCustomer.CustomerID AND tblEvent.EventDate BETWEEN @fromDate  AND @toDate;

            List<SqlParameter> lstParams = new List<SqlParameter>();

            lstParams.Add(new SqlParameter("@fromDate", FromDate));
            lstParams.Add(new SqlParameter("@toDate", ToDate));

            return DBUtility.SelectData(query, lstParams)";
        }

This should work fine i guess!

