I have a page where I am trying to populate a gridview (gvClockings) on a button click based upon a selection in a dropdownlist (cbLocation) and a from/to date entered into textboxes from a calendarextender (txtFrom and txtTo).
I have tested the SQL statement and it gets the expected results if I run it in Access (and I have similar SQL working fine with a gridview on a different form in this solution), however on this form no matter what I select in the 3 controls, the gridview will not display any records.
cbLocation is populated in Page_Load as below:
If Not Page.IsPostBack Then
Dim ddl As DropDownList = cbLocation
Dim ir As ListItem = New ListItem
Dim ee As ListItem = New ListItem
ir.Text = "IR Room"
ir.Value = "IR Room"
ee.Text = "Employee Exit"
ee.Value = "Employee Exit"
ddl.Items.Add(ir)
ddl.Items.Add(ee)
End If
I then have the below code to get the data and populate the gridview:
Private Sub GetClockings(ByVal LLName As String, ByVal FromDate As String, ByVal ToDate As String)
Dim conclock As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=\\xxx.xx.xxx.xx\AccuFace\pspcms.mdb;Jet OLEDB:Database Password=xxxxx;")
Dim daClocking As OleDbDataAdapter = New OleDbDataAdapter
Dim selectSQL As String = "SELECT efrLog.LFirstName, efrLog.LLastName, efrLog.LDepartment, efrLog.LDate, efrLog.LTime, efrLog.LType, efrLog.LLName FROM efrLog WHERE (((efrLog.LDate) Between [@FROMDATE] And [@TODATE]) AND ((efrLog.LLName)=[@LLName])) ORDER BY efrLog.LDepartment, efrLog.LTime"
Dim selectCMD As OleDbCommand = New OleDbCommand(selectSQL, conclock)
daClocking.SelectCommand = selectCMD
selectCMD.Parameters.AddWithValue("@LLName", LLName)
selectCMD.Parameters.AddWithValue("@FROMDATE", FromDate)
selectCMD.Parameters.AddWithValue("@TODATE", ToDate)
Dim dsClockings As DataSet = New DataSet
daClocking.Fill(dsClockings, "efrLog")
If dsClockings.Tables("efrLog").Rows.Count > 0 Then
gvClockings.DataSource = dsClockings.Tables("efrLog")
gvClockings.DataBind()
Else
lblNotFound.Text = "No clockings found for this location"
lblNotFound.Visible = True
Exit Sub
End If
End Sub
The above code is called from Button_click as below:
Dim LLName As String
Dim FromDate As String = txtFrom.Text
Dim ToDate As String = txtTo.Text
If cbLocation.SelectedValue = "IR Room" Then
LLName = "IR Room"
GetClockings(LLName, FromDate, ToDate)
End If
If cbLocation.SelectedValue = "Employee Exit" Then
LLName = "Employee Exit"
GetClockings(LLName, FromDate, ToDate)
End If
lblLocation.Text = "Clocking report for " & cbLocation.SelectedValue.ToString() & " generated on " & Date.Now
lblLocation.Visible = True
I have debugged locally as far as I can (I am using an access db on a remote server from IIS so get connection string/permission-related errors when trying to fill the dataset when running locally. I know it's a horrible setup but it's what I have been given to work with and I don't know how to debug remotely) and as far as I can see, the parameters appear to be receiving the correct values (see below)
The data I am requesting from the db definitely exists so I'm completely stuck as to why the gridview isn't populating. Any help would be gratefully received. Thanks