我有一个问题,我想从访问记录中向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()
答案 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,如果它是唯一的,也应该在某个地方使用。