I am using MS Access database and VB.NET to query data from a table. Results appear correctly in MS Access, but no records are displayed in the DataGridView. I have included the SQL query and screenshots of the results from MS Access and DataGridView. I have also included the code used for population.
Fenced Code Blocks
SQL Query:
SELECT EmpID, [Name], TotalCPI, RangeSalary
FROM Query1 AS E INNER JOIN (SELECT Left(RangeCPI,3) AS Start, Mid(RangeCPI,5,3) + 1 AS [End], RangeSalary
FROM tblPayrollDecision) AS PD ON (E.TotalCPI < PD.End) AND (E.TotalCPI >= PD.Start);
Population Code:
Public Sub filltable(ByVal dtgrd As Object, ByVal design As String)
Dim publictable As New DataTable
Try
da.SelectCommand = cmd
da.Fill(publictable)
dtgrd.DataSource = publictable
Select Case design
Case "EmpInfo"
dtgrd.Columns(0).Visible = False
End Select
da.Dispose()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
End Try
End Sub
Public Sub jokenselect(ByVal sql As String)
Try
con.Open()
With cmd
.Connection = con
.CommandText = sql
End With
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
con.Close()
da.Dispose()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
jokenselect("Select * From Query2")
filltable(DataGridView1, "EmpPic")
End Sub