I believe something is wrong with my coding. It’s not filtering by date I guess. Please help
SQL code:
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)
C# code:
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 (InvDate >= CONVERT(datetime, '" + dtpFrom.Text + "', 105 ))
AND (InvDate <= CONVERT(datetime, '" + dtpTo.Text + "', 105))," , objConn);
This is what I want to achieve:
This is what I get:
Before i get kicked from here. I’ll make some edits.
EDIT:
DateTime is in a 105 format (dd-mm-yyyy)
WHERE (InvDate >= CONVERT(datetime, '" + dtpFrom.Text + "', 105 ))
AND (InvDate <= CONVERT(datetime, '" + dtpTo.Text + "', 105))
This is supposed to choose from a particular date. EG: from 11 Oct 2012 to 15 Oct 2012.
Even without DateTimepicker, The output doesn’t show me “GivenName”


The best way is to format your input in dd/MMM/yyyy format. It better helps SqlServer to identify the month and day. I strongly recommend to use MMM format whenever you communicate with SqlServer.
or if you have any constraint to do as above, convert the input using CONVERT()