为什么在Form2中,使用Dapper和MS Access在VB.NET中填充DataGridView时不显示?

huangapple go评论75阅读模式
英文:

why datagridview in form2 doesn't appear population with dapper MS-Acess in VB.NET

问题

为什么在Form2中,使用Dapper和MS-Access在VB.NET中填充DataGridView不显示?

如果我将DataGridView的数据源更改为GetItem()函数,然后数据就会显示在DataGridView中。我的代码有问题吗?请指导一下。

谢谢!

英文:

why datagridview in form2 doesn't appear population with dapper MS-Acess in VB.NET?

if I change the datasource datagridview to the GetItem() function then the population appears in the datagridview. Is there something wrong with my code? . Please Guide

Thanks

'iN Form1

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Form2.Show()
    End Sub

'in FORM2
 Private iService As New Itemservice2()
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        DataGridView1.DataSource = iService.Getitem2(Form1.Btxtcodeproduct.Text)
    End Sub
End Class
 Public Function Getitem() As IEnumerable(Of Stocks)
        Dim sql = "SELECT * FROM Stocks"
        Using _conn = New OleDbConnection(DbContext.GetOledbConnectionString())
            Return _conn.Query(Of Stocks)(sql).ToList()
        End Using
    End Function
 Public Function Getitem2(ByVal code As String) As Stocks
        Dim sql = $"SELECT * FROM Stocks WHERE CodeProduct = '{code}'"
        Using _conn = New OleDbConnection(DbContext.GetOledbConnectionString())
            Return _conn.Query(Of Stocks)(sql).FirstOrDefault()
        End Using
    End Function
Public Class Stocks
    Public Property Id() As Integer
    Public Property CodeProduct() As String
    Public Property Colorcode() As String
    Public Property Size() As String
    Public Property Qty() As Integer

End Class

为什么在Form2中,使用Dapper和MS Access在VB.NET中填充DataGridView时不显示?

result datagridview in form2 with function getitem()

为什么在Form2中,使用Dapper和MS Access在VB.NET中填充DataGridView时不显示?

答案1

得分: 1

根据@dr.null的指南,我得到了完美的答案

 Public Function Getitem2(ByVal code As String) As IEnumerable(Of Stocks)
        Dim sql = $"SELECT * FROM Stocks WHERE CodeProduct = '{code}'"
        Using _conn = New OleDbConnection(DbContext.GetOledbConnectionString())
            Return _conn.Query(Of Stocks)(sql).ToList()
        End Using
    End Function
英文:

in accordance with the guidelines of @dr.null
then I got the perfect answer

 Public Function Getitem2(ByVal code As String) As IEnumerable(Of Stocks)
        Dim sql = $"SELECT * FROM Stocks WHERE CodeProduct = '{code}'"
        Using _conn = New OleDbConnection(DbContext.GetOledbConnectionString())
            Return _conn.Query(Of Stocks)(sql).ToList()
        End Using
    End Function

huangapple
  • 本文由 发表于 2023年7月12日 22:36:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76671744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定