Так зачем вы выполняете запрос, если не инициализируете query?
var dateFromString = txtSelectByDate1.Text;
var dateToString = txtSelectByDate2.Text;
if (!string.IsNullOrEmpty(dateFromString) && !string.IsNullOrEmpty(dateToString))
{
var dateFrom = Convert.ToDateTime(dateFromString).ToString("yyyy-MM-dd");
var dateTo = Convert.ToDateTime(dateToString).ToString("yyyy-MM-dd");
var query = string.Format("Select * from Purchase where P_Date >= '{0}' and P_Date <= '{1}'", dateFrom, dateTo);
var command = new SqlCommand(query, cn);
var adapter = new SqlDataAdapter(command);
var table = new DataTable();
adapter.Fill(table);
gvPurchase.DataSourceID = null;
gvPurchase.DataSource = table;
}