内连接2个表如何在vb.net中的MS-ACCESS数据库中使用dapper显示datagridview中的特定字段

问题描述 投票:0回答:1

为什么 StocksoutDetail 表中的“codeproduct”没有出现在 datagridview 中,是我的代码有问题吗?为什么在 datagridview 中出现另一个字段,即使我没有在 SQL 中选择该字段。请指导我

谢谢

Public Class Form1
    Private sosservice As New StocksoutService()
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        DataGridView1.DataSource = sosservice.GetStockOut()
    End Sub
End Class
Public Class StocksoutService
    Public Function GetOledbConnectionString() As String
        Return "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\dapperdemo.accdb;Persist Security Info=False;"
    End Function
    Private ReadOnly _conn As OleDbConnection
    Private _connectionString As String = GetOledbConnectionString()
    Public Sub New()
        _conn = New OleDbConnection(_connectionString)
    End Sub
    Public Function GetStockOut() As IEnumerable(Of Stocksout)
        Dim sql = "SELECT Stocksout.Invno AS [Invno],StocksoutDetail.CodeProduct AS [CodeProduct] FROM Stocksout INNER JOIN StocksoutDetail ON Stocksout.Invno = StocksoutDetail.Invno"
        Using _conn = New OleDbConnection(GetOledbConnectionString())
            Return _conn.Query(Of Stocksout)(sql).ToList()
        End Using
    End Function
End Class
Public Class Stocksout
    Public Property Invno() As String
    Public Property HeaderInvno() As Integer
    Public Property CreatedBy() As String
    Public Property Created() As DateTime
    Public Property ModifiedBy() As String
    Public Property Modified() As DateTime
    Public Property StocksoutDetail() As New List(Of StocksoutDetail)()
End Class
Public Class StocksoutDetail
    Public Property Id() As Integer
    Public Property No() As Integer
    Public Property Invno() As String
    Public Property CodeProduct() As String
    Public Property Barcode() As String
    Public Property Colorcode() As String
    Public Property Size() As String
    Public Property Qty() As Integer
End Class

sql vb.net ms-access datagridview dapper
1个回答
0
投票

根据@HardCode的指导方针和建议

  Private sosservice As New StocksoutService()
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        DataGridView1.DataSource = sosservice.GetStockOut()
    End Sub

    Public Function GetStockOut() As IEnumerable(Of DTOStocksout)
        Dim sql = "SELECT Stocksout.Invno AS [Invno],StocksoutDetail.CodeProduct AS [CodeProduct] FROM Stocksout INNER JOIN StocksoutDetail ON Stocksout.Invno = StocksoutDetail.Invno"
        Using _conn = New OleDbConnection(GetOledbConnectionString())
            Return _conn.Query(Of DTOStocksout)(sql).ToList()
        End Using
    End Function
Public Class DTOStocksout
    Public Property Invno() As String
    Public Property CodeProduct() As String

End Class
© www.soinside.com 2019 - 2024. All rights reserved.