sql tables in database

is it possible to get list of tables in database? thanks
[56 byte] By [mackenzie2480] at [2007-12-22]
# 1

yes....

Public Overrides Function GetSchema(ByVal collectionName As String) As System.Data.DataTable

Member of: System.Data.SqlClient.SqlConnection

Summary:Returns schema information for the data source of this System.Data.SqlClient.SqlConnection using the specified string for the schema name.Parameters:

collectionName: Specifies the name of the schema to return.Return Values:

A System.Data.DataTable that contains schema information.

DMan1 at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

SQL Statement will return you the list of tables in a selected/using database:

SELECT name FROM sysobjects WHERE type = 'U'

you can execute this command in the SQL Command, and then fill the datatable with the results using a SqlDataAdapter

Dim theSQLCommand as new SqlCommand("SELECT name FROM sysobjects WHERE type = 'U')

Dim theDataSet as new DataSet()

Dim theDataAdapter as new SqlDataAdapter(theSQLCommand)

theSqlCommand.Connection = new SqlConnection(connectionString)

theSqlCommand.Connection.Open()

theDataAdapter.Fill(theDataSet)

theSqlCommand.Connection.Close()

results should now be stored in:

theDataSet.Tables(0)

does this help?

ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

yes thank you both. it works now right, but what if i want results to combobox. now it shows just some text. i guess the problem is displaymember property.

mackenzie2480 at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4

to display it in a combo box:

Me.theComboBox.DataSource = theDataTable.DefaultView

Me.theComboBox.DisplayMember = theFieldName

Now, if you are using the datatable approach, then this is fine. Be sure to modify the displaymember property to tell it to "bind" a specific column, such as "Name" from my example

does this help?

ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 5
oh that was so easy, i should've figured it out. thank you very much. this helped a lot.
mackenzie2480 at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 6
no worries, glad I could help ;-)
ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...