VB.net |如何将访问数据库记录转换为tabcontrol添加标签页?

时间:2014-06-25 18:29:37

标签: vb.net visual-studio-2010 visual-studio ms-access-2010

我有一个问题,我想从访问记录中向TabPage添加TabControl?我认为它是这样的,但它不起作用:

    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()

1 个答案:

答案 0 :(得分:0)

您必须遍历表的行集合:

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

当然,这只会为每个记录提供一个空的TabPage,并且在当前的实现中,您不再对该记录有任何引用。 ProductType,如果它是唯一的,也应该在某个地方使用。