Below code will provide you the table name of the SQL server for the current database.
You just need to pass required parameter to connect to the database.
Protected Sub getTables()
Dim dbconn As SqlConnection
Dim sql As String
Dim Command As SqlCommand
dbconn = New SqlConnection("server=" & txtserver.Text.Trim & ";uid=" & txtuid.Text.Trim & ";pwd=" & txtpwd.Text.Trim & ";database=" & txtdatabase.Text.Trim & "")
dbconn.Open()
sql = "SELECT * FROM sys.tables where type='U'"
Command = New SqlCommand(sql, dbconn)
Dim dtAdapter As New SqlDataAdapter
Dim dtTable As New DataTable
dtAdapter.SelectCommand = Command
dtAdapter.Fill(dtTable)
chkTable.DataSource = dtTable
chkTable.DataTextField = "name"
chkTable.DataBind()
Dispose()
End Sub
So from above code, you will have a all SQL table list in the DataTable object chkTable.
Try out below code for getting individual table column name.
For Each item As ListItem In chkTable.Items
If item.Selected Then
dbconn.Open()
sql = "SELECT * FROM " & item.Text
Command = New SqlCommand(sql, dbconn)
Dim dtAdapter As New SqlDataAdapter
Dim dtTable As New DataTable
dtAdapter.SelectCommand = Command
dtAdapter.Fill(dtTable)
Dispose()
dbconn.Close()
End If
Next
Hope it helps.