首页 > 解决方案 > 我的用户控件列表视图从 msaccess 填充数据的问题

问题描述

我通过 vb.net 在我的访问数据库中创建了 listview ms activex 我在 vb.net 中添加了该代码以填充我的 listview

Public Sub FillListview(ByVal CurrntDb As String)
          Dim conn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim da As OleDbDataAdapter
    Dim ds As DataSet
    Dim itemcoll(100) As String
    ListView1.View = View.Details
    ListView1.GridLines = True
    ListView1.Items.Clear()
    conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & CurrntDb)
    Dim strQ As String = String.Empty
    strQ = "SELECT Accounts.ID AS [م], Customers.Customer  AS [العميل], Accounts.Debit  AS [مدين], Accounts.Credit  AS [دائن], Accounts.Dates  AS [التاريخ], Accounts.Notes  AS [البيان] FROM Accounts INNER JOIN Customers ON Accounts.Customer_ID = Customers.Customer_ID;"
    cmd = New OleDbCommand(strQ, conn)
    da = New OleDbDataAdapter(cmd)
    ds = New DataSet
    conn.Open()
    da.Fill(ds)
    Dim i As Integer = 0
    Dim j As Integer = 0
    ' adding the columns in ListView
    For i = 0 To ds.Tables(0).Columns.Count - 1
        ListView1.Columns.Add(ds.Tables(0).Columns(i).ColumnName.ToString())
    Next
    'Now adding the Items in Listview
    For i = 0 To ds.Tables(0).Rows.Count - 1
        For j = 0 To ds.Tables(0).Columns.Count - 1
            itemcoll(j) = ds.Tables(0).Rows(i)(j).ToString()
        Next
        Dim lvi As New ListViewItem(itemcoll)
        ListView1.Items.Add(lvi)
        ListView1.Refresh()
    Next
    conn.Close()
 
End Sub

并在我的访问数据库中注册它并通过该代码在访问代码中调用它

    Dim xlist As New AForTestListviewBySedo.UserControl1
    Call xlist.FillListview("C:\Users\Elsayed\Desktop\New folder\mydb.accdb")

但他们什么也没有给我,不是错误,但什么也没有

我通过在其中添加按钮测试了用户控件中的代码按钮效果很好

我能做些什么 ?

标签: vb.netms-accessuser-controls

解决方案


解决方案是使用我的代码访问通话记录我需要首先设置对象正确的代码是

Option Explicit
  Option Compare Database
Public listv As MsAccessListviewACX1_00.UCBySedo
Public Sub LoadListview()
Set listv = Me.UCBySedo9.Object
listv.FillListview ("C:\Users\Elsayed\Desktop\New folder\mydb.accdb")
End Sub
Private Sub Command115_Click()
Call LoadListview
End Sub

推荐阅读