
This functions returns all sql tables from a given connection as a list of string.
Public Shared Function GetTableList(ByVal strCon As String) As List(Of String) ' Create result Dim lstResult As New List(Of String) Try Using con As New SqlClient.SqlConnection(strCon) Try con.Open() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical) End Try ' Create command and execute it Dim cmd As New SqlClient.SqlCommand("SELECT Table_Name FROM Information_Schema.Tables", con) Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader ' Add all columns to our list Do While dr.Read lstResult.Add(dr("Table_Name").ToString) Loop End Using Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical) End Try Return lstResult End Function
0 Antworten zu Get all tables from a sql server