简体   繁体   English

VB.net | 我怎样才能把一个访问数据库记录变成一个tabcontrol添加tab页?

[英]VB.net | how can i turn an access db record in to a tabcontrol add tabpage?

I have a question, I want to add a TabPage to my TabControl from an access record? 我有一个问题,我想从访问记录中将TabPage到我的TabControl吗? I think it's something along these lines but it didn't work: 我认为这是沿着这些思路的事情,但是没有用:

    Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\data\testing.Accdb;Persist Security Info=False;")
    con.Open()
    Dim constr As String = "SELECT ProductType, Discription FROM TblProductType"
    Dim cmd As OleDbCommand = New OleDbCommand(constr, con)
    Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
    Dim ds As DataSet = New DataSet()
    da.Fill(ds, "TblProductType")


    Me.TabControl1.TabPages.Add("Discription")

    con.Close()

You have to iterate over the row collection of the table: 您必须遍历表的行集合:

Using cmd As New OleDbCommand("SELECT ProductType, Discription FROM TblProductType", con)
  Using rdr As OleDbDataReader = cmd.ExecuteReader
    While rdr.Read
      TabControl1.TabPages.Add(rdr("Discription").ToString)
    End While
  End Using
End Using

Of course, this only gives you an empty TabPage for every record and in it's current implementation, you don't have any reference to the record anymore. 当然,这只会为每个记录提供一个空的TabPage,在当前的实现中,您将不再有对该记录的引用。 That ProductType, if it's unique, should be used somewhere, too. 该ProductType如果是唯一的,也应该在某个地方使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM