英文:
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
result datagridview in form2 with function getitem()
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论