why the Integer ID doesn't load correctly in datagridview with dapper in vb.net with access database. whether there is another solution or should code function so that the ID appears in datagridview. The datagridview in my code uses nuget packages "Kimtoo.Bindingprovider" and I also use nuget packages dapper with an Access database.
Public Class TEST
Public Property Id() As Integer
Public Property Itemproduct() As String
Public Property Quantity() As Integer
End Class
Public Class Form1
Private record As TEST
Public Function GetConnectionString() As String
Dim strCon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|"
strCon &= "\DB_TEST.accdb;Persist Security Info=False;"
Return strCon
End Function
Public Con As New OleDbConnection(GetConnectionString())
Private Sub LoadData()
Try
Dim data As List(Of TEST) = Con.Query(Of TEST)("Select * From TEST").ToList()
'DataGridView1.Bind(data)
DataGridView1.DataSource = data
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadData()
End Sub
CodePudding user response:
The column name is ID
(upper-case) in the Access database. In class TEST
, change Id
to ID
Public Class TEST
Public Property ID As Integer
Public Property Itemproduct As String
Public Property Quantity As Integer
End Class
Additional Resources