Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
cmbtableNames.DisplayMember = "Text"
Dim con As New SqlConnection("User ID=sa;pwd=secrate;Initial Catalog=Mydb;Data Source=customer")
Dim SchemaAdapter As New SqlDataAdapter("SELECT table_name,table_Schema FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME", con)
con.Open()
Dim Schematable As New DataTable
SchemaAdapter.Fill(Schematable)
Dim i As Long
For i = 1 To Schematable.Rows.Count - 1
'cmbtableNames.Items.Add(Schematable.Rows(i).Item("TABLE_NAME").ToString) 'add the tablenames
cmbtableNames.Items.Add(New MyItem(Schematable.Rows(i).Item("TABLE_NAME").ToString, Schematable.Rows(i).Item("table_Schema").ToString))
Next
Schematable.Dispose()
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'FUNCTION TO DISPLAY THE TABLE INFORMATION WITH RESPECT TO TABLENAME
Private Sub DisplayTableInformation(ByVal tablename As String, ByVal owner As String)
Try
'Function to display the table information
'Add a datagridview control
Dim con As New SqlConnection("User ID=sa;pwd=secrate;Initial Catalog=Mydb;Data Source=customer")
Dim SQL As String
'SQL = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" & tablename & "'"
SQL = "SELECT * FROM " & owner & "." & tablename
Dim SchemaAdapter As New SqlDataAdapter(SQL, con)
con.Open()
Dim Schematable As New DataTable
'Dim Schematable As New DataSet
SchemaAdapter.Fill(Schematable)
SchemaAdapter.Fill(Schematable)
DataGridView1.DataSource = Schematable
Schematable.Dispose()
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub cmbTablenames_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbtableNames.SelectedIndexChanged
'declare a copy of your subclass
Dim AnItem As MyItem
'cast the incoming node into your subclass
AnItem = CType(cmbtableNames.SelectedItem, MyItem)
DisplayTableInformation(cmbtableNames.Text, AnItem.MyStrng)
End Sub
Class MyItem
'Since all we need is a "Text" property for this example we can
'Subclass by inheriting any object desired.
'For this example, we'll use the ListViewItem
Inherits ListViewItem
'each of the below public declarations will be "visible" to the outside
'You may add as many of these declarations using whatever types you desire
Public MyShowText As String
Public MyStrng As String
'every value of MyInfo you want to store, get's added to the NEW declaration
Sub New(ByVal ShowText As String, ByVal Strng As String)
MyBase.New()
'transfer all incoming parameters to your local storage
MyShowText = ShowText
MyStrng = Strng
'and finally, pass back the Text property
Me.Text = MyShowText
End Sub
End Class
End Class