La meilleure façon est de formater votre entrée en jj/MMM format /aaaa. Cela aide mieux SqlServer à identifier le mois et le jour. Je recommande fortement d'utiliser le format MMM chaque fois que vous communiquez avec SqlServer.
DateTime fromDate, toDate;
fromDate = DateTime.Parse(dtpFrom.Text);
toDate = DateTime.Parse(dtpTo.Text);
SqlCommand objCmd = new SqlCommand("SELECT CONVERT(char(80), i.InvDate,3) AS InvDate,
i.InvoiceNo,
i.EmployerCode,
i.TaxAmount + i.SubTotal AS Amount,
'' AS Payment,
pd.GivenName
FROM dbo.Invoice i
INNER JOIN dbo.PatientDetails pd ON (pd.MedicalRecordID = i.MedicalRecordID)
WHERE datediff(d, '" + fromDate.ToString("dd/MMM/yyyy") + "', i.InvDate) >=0
AND datediff(d, '" + toDate.ToString("dd/MMM/yyyy") + "', i.InvDate) <=0", objConn);
ou si vous avez une contrainte à faire comme ci-dessus, convertissez l'entrée en utilisant CONVERT()
SqlCommand objCmd = new SqlCommand("SELECT CONVERT(char(80), i.InvDate,3) AS InvDate,
i.InvoiceNo,
i.EmployerCode,
i.TaxAmount + i.SubTotal AS Amount,
'' AS Payment,
pd.GivenName
FROM dbo.Invoice i
INNER JOIN dbo.PatientDetails pd ON (pd.MedicalRecordID = i.MedicalRecordID)
WHERE datediff(d, CONVERT(datetime, '" + dtpFrom.Text + "', 105 ), i.InvDate) >=0
AND datediff(d, CONVERT(datetime, '" + dtpTo.Text + "', 105 ), i.InvDate) <=0", objConn);