Saturday, February 25, 2012

Connecting the ASP.Net to a DB using SQL Query

I have a SQL query that I think it wont work it's:

SELECT break_time, break_rep_no, break_count, break_update_count, break_type, break_group
FROM breaks
WHERE (break_date = @.p1) AND (break_group = @.p2) AND (break_time > @.p3) OR
(break_time < @.P4)
ORDER BY break_time

When I insert this parameters:

@.p1= 7/21/2004
@.p2= 0
@.p3= 9:00 AM
@.p4= 3:00 PM

I get these results:
Break_time rep_no count ucount break_type break_group
9:00:00 AM____2____2_____0________2_________0
9:00:00 AM____2____2_____1________1_________0
10:00:00 AM___1____2_____0________2_________2
11:20:00 AM___2____1_____0________2_________2
1:00:00 PM____2____2_____1________1_________0

Which if you notice not the result I expect look at the (break_group) Column you will find that it brings 0's in addition to 2 which is not expected to appears?

I'm using this query in ASP.Net page Under VB.Net

Me.SqlComm_Chk_Group.Parameters(0).Value = System.DateTime.Today
Me.SqlComm_Chk_Group.Parameters(1).Value = 0
Me.SqlComm_Chk_Group.Parameters(2).Value = tFrom.AddMinutes(59).ToShortTimeString()
Me.SqlComm_Chk_Group.Parameters(3).Value = tTo.AddMinutes(-59).ToShortTimeString()

dr = Me.SqlComm_Chk_Group.ExecuteReader

While dr.Read
tBreakTime = dr(0)
iRepNo = dr(1)
iBreakCount = dr(2)
iBreakUCount = dr(3)
iBreakType = dr(4)
iBreakGreoup = dr(5)

Call Engine(tBreakTime, tFrom, iBreakType, False, iRepNo)
End While
dr.Close()

Where is the problem PLAES?
Thank youParenthesize.


SELECT break_time, break_rep_no, break_count, break_update_count, break_type, break_group
FROM breaks
WHERE (break_date = @.p1) AND (break_group = @.p2) AND ((break_time > @.p3) OR
(break_time < @.P4))
ORDER BY break_time

Even now, I am not sure the code will do what you are looking to do.|||Why I did it before and it works I even try it with OleDB with MSAccess DB But I'm not understand why its not working here every thing seems to be correct|||Depending upon the data in the db and the times you pass, it might APPEAR to work for some data.

No comments:

Post a Comment