De beste manier is om uw invoer op te maken in dd/MMM /jjjj formaat. Het helpt SqlServer beter om de maand en dag te identificeren. Ik raad ten zeerste aan om het MMM-formaat te gebruiken wanneer u communiceert met 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);
of als je beperkingen hebt om te doen zoals hierboven, converteer de invoer dan met 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);