Quote (carteblanche @ Oct 16 2014 07:21pm)
Yeah I actually fixed the problem, for all of my other access queries I have used named parameters and it worked, but not this one
Now my problem is actually filling the datatable, I guess they don't like Pivot queries very much
My problem now is still the same, but for a different reason, the query works correctly and the parameters pass through, but the data is not being loaded into the DataTable
So basically my next problem is a lot more difficult
This is the new function
Code
Public Function GetUserDetail(ByVal user As String, ByVal ndate As Date) As DataTable
Dim dt As New DataTable
Using conn As New OleDbConnection(accessConn)
Dim cmdtext As String = vbNullString
cmdtext = "TRANSFORM Count(Log.ControlNumber) AS CountOfCtrl "
cmdtext = cmdtext + "SELECT Log.StartStatus, Log.EndStatus, Count(Log.ControlNumber) AS TOTAL "
cmdtext = cmdtext + "FROM(Log) "
cmdtext = cmdtext + "WHERE (((Log.User) = ?) AND ((DateValue([DateChanged])) = ?)) "
cmdtext = cmdtext + "GROUP BY Log.StartStatus, Log.EndStatus "
cmdtext = cmdtext + "PIVOT Hour(Format([DateChanged],'Short Time'));"
Dim cmd As New OleDbCommand(cmdtext, conn)
cmd.Parameters.AddWithValue("user", user)
cmd.Parameters.AddWithValue("date", ndate.ToString("MM-dd-yyyy"))
conn.Open()
Dim rdr As OleDbDataReader = cmd.ExecuteReader
'dt.Load(rdr) // Commented out to test other methods
'Test Area
Do While rdr.Read
Dim dr As DataRow = dt.NewRow
For i = 0 To rdr.FieldCount - 1
dr.Item(i) = rdr.Item(i)
Next
dt.Rows.Add(dr)
Loop
'End Test Area
conn.Close()
Return dt
End Using
End Function
This has helped me locate the problem, the DoWhile never initiates, it gets called, but the reader never reads.
When I use dt.Load, I still get the column names, but no Pivot columns, which should be 0 (12:00 AM), 1 (1:00 AM), 2 (2:00 AM), etc..
So I think the problem is the datareader
I am considering loading the data into an xcel file and displaying the excel file, but I really do not want to do this