Hello Friends,

I am messed up with the below query

Try
    Dim myCommand As OleDbCommand
    myCommand = New OleDbCommand("select sum(tmt.total) as Total from Appointment appt, TreatmentMaster tmt where appt.patientid='" + txtPatIDBill.Text + "' and [tmt].[treatid]=[appt].[treatmentid] and (Format([appt.ApptDate], 'Short Date')) between '" + dtpFromBill.Value.Date + "' and  '" + dtpToBill.Value.Date + "'", Connection)
    Dim reader As OleDbDataReader = myCommand.ExecuteReader
    Debug.Print("Query output: " + myCommand.CommandText)
    If reader.Read = True Then
       Debug.Print("True")
    Else
       Debug.Print("False")
    End If
Catch ex As Exception
    MsgBox("Error Connecting to Database: " & ex.Message)
End Try

I have to select the patientid, from date and the to date from the GUI part....

I have values in Database for date 2/20/2012 and 2/22/2012

whenever I try to run the query in Access it is returning the correct data...

but when i run the query in my project the reader in not reading correctly...even if values are present is returns false
and if values are not there then it returns true....

I am not getting where I am going wrong...
Please help me...

Recommended Answers

All 10 Replies

hello !
do you try dtpFromBill.Value.Date.tostring() instead of this dtpFromBill.Value.Date .

Regards

and please try this query , may be this will solve your prob .

"select sum(tmt.total) as Total from Appointment appt inner join  TreatmentMaster tmt on  [tmt].[treatid]=[appt].[treatmentid] where appt.patientid='" + txtPatIDBill.Text + "' and [appt.ApptDate] between '" + dtpFromBill.Value.Date.tostring() + "' and  '" + dtpToBill.Value.Date.tostring() + "'"

and please try this query , may be this will solve your prob .

"select sum(tmt.total) as Total from Appointment appt inner join  TreatmentMaster tmt on  [tmt].[treatid]=[appt].[treatmentid] where appt.patientid='" + txtPatIDBill.Text + "' and [appt.ApptDate] between '" + dtpFromBill.Value.Date.tostring() + "' and  '" + dtpToBill.Value.Date.tostring() + "'"

I got the answer...but I need help on how to proceed....

Actually when I take some other date that is not there in database the 'sum(tmt.total) as Total ' returns a null value and therefore the reader takes it as true...

but if I remove the sum and just write '(tmt.total) as Total' then no records are retrieved and it returns false that is correct...but I need the sum for calculation....

so I need to know how shud I proceed....

and please try this query , may be this will solve your prob .

"select sum(tmt.total) as Total from Appointment appt inner join  TreatmentMaster tmt on  [tmt].[treatid]=[appt].[treatmentid] where appt.patientid='" + txtPatIDBill.Text + "' and [appt.ApptDate] between '" + dtpFromBill.Value.Date.tostring() + "' and  '" + dtpToBill.Value.Date.tostring() + "'"

I tried this also using

Debug.Print("Date: " + dtpToBill.Value.Date.ToString)

If I use the to String method then I will also get the time along with the date
Date: 2/24/2012 12:00:00 AM

try this may be this will helps you

If reader.Read = True Then
dim a as integer
 a = val(reader.read).tostring()
if a <> null then 
   Debug.Print("True")
endif
    
    Else
       Debug.Print("False")
    End If

this is just an idea , so please check it by your self .

Regards

try this may be this will helps you

If reader.Read = True Then
dim a as integer
 a = val(reader.read).tostring()
if a <> null then 
   Debug.Print("True")
endif
    
    Else
       Debug.Print("False")
    End If

this is just an idea , so please check it by your self .

Regards

I used formatting for datetimepicker....my issue has been solved...

if your prob is solved then please mark this thread solved :)
Regards

if your prob is solved then please mark this thread solved :)
Regards

Ya sure....thank u....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.