Thursday, December 29, 2011

resizing array at runtime in vb.net - Stack Overflow

I was just coding along today in VB.Net and realized that I sure would like to build a list during runtime based on the names of the tables in any database passed to it but with the flexibility of not knowing how many tables are in it. Turn out that there is a way. The link is at the end after my code.


Dim Tablelist as New List(Of String)()
Dim odbcconn As OleDb.OleDbConnection=New oledb.OleDbConnection(connstring)
Dim restrictions(3) As string
restrictions(3) = "MSYS"
odbcconn.Open()
Dim dt As DataTable = odbcconn.GetSchema("Tables")
For Each dr In dt.rows
If InStr(Ucase(dr("TABLE_NAME")),"MYS") = 0 then
Tablelist.Add(dr("TABLE_NAME"))
End If
Next
odbcconn.Close


First a list of tables are returned from the connection object and then all tables that do not contain the string "MYS" in it's name are filled in to the TableList.

resizing array at runtime in vb.net - Stack Overflow
Enhanced by Zemanta

No comments: