提问人:siwa86 提问时间:10/29/2023 最后编辑:Amit Joshisiwa86 更新时间:10/31/2023 访问量:38
如何在 dapper 中使用 VB.NET 从两个列表/类自动生成 datagridview 中的列,而无需在 dapper 中使用数据传输对象
How to autogenerate columns in datagridview from two list/class without data transfer object in dapper with VB.NET
问:
我正在尝试在 datagridview 中自动生成列,而无需在 dapper 中使用数据传输对象 VB.NET
我有下面的代码。
有没有其他方法请指导我。
我可以使用类的解决方案 但是,如果没有数据传输对象类模型,可以实现什么dtoOrder
谢谢
Public Class Form1
Private bindingSource As BindingSource = Nothing
Private resultList As IEnumerable(Of Order) = Nothing
Private connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Autogeneratecolumdgvdapper.accdb;Persist Security Info=False;"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.AutoGenerateColumns = True
Using conn = New OleDbConnection(connectionString)
conn.Open()
Dim sql = "SELECT O.Invono AS [Invono],O.InvnoDate AS [InvnoDate], OD.CodeProduct AS [CodeProduct],OD.Qty AS [Qty] FROM [Order] O
INNER JOIN [Orderdetail] OD ON OD.Invono = O.Invono"
resultList = conn.Query(Of Order)(sql).ToList()
conn.Close()
End Using
bindingSource = New BindingSource With {.DataSource = New BindingList(Of Order)(CType(resultList, IList(Of Order)))}
DataGridView1.DataSource = bindingSource
End Sub
End Class
Public Class Order
Public Property Invono() As String
Public Property InvnoDate() As DateTime
Public Property Order() As New List(Of Orderdetail)()
End Class
Public Class Orderdetail
Public Property Invono() As String
Public Property CodeProduct() As String
Public Property Qty() As Integer
End Class
Public Class dtoOrder
Public Property Invono() As String
Public Property InvnoDate() As DateTime
Public Property CodeProduct() As String
Public Property Qty() As Integer
End Class
答: 暂无答案
评论