Hi,
Now i can access to any table in my data base, but i want that the
user choose a table.
So i need to make a code that allow me to browser all the database
tables.
Omar Abid
Like I mentioned in my last post, what you need to do to get the table
names is query the schema tables. Use something like this as:
Select Distinct TABLE_NAME
From INFORMATION_SCHEMA.COLUMNS
You'll need to mess around with the Where statement to get rid of
system tables, etc, but I don't have Sql Server available right know
to help.
Thanks,
Seth Rowe
---------------------------------------------------
Here ya go.
Dim cn As New SqlConnection(connectionString)
Try
cn.Open()
'The Restrictions are: table_catalog, table_schema,
' table_name, table_type.
'For my case, the table_catalog is the database name.
'table_Schema is the owner.
'Table_name is nothing because I want all tables.
'table_type is "BASE TABLE".
Dim restrictions() As String = New String() _
{My.Settings.DatabaseName, "dbo", Nothing, "BASE TABLE"}
Dim dt As DataTable = cn.GetSchema("Tables", restrictions)
'Uncomment this if you want to see the columns you can
' access from the GetSchema command.
'I'm leaving it in here for future reference.
'For Each col As DataColumn In dt.Columns
' Debug.Print(col.ColumnName.ToString)
'Next
For Each rw As DataRow In dt.Rows
'Uncomment this if you want to see the values
' for each of these columns.
'I'm leaving it in here for future reference.
'Debug.Print("Table_Catalog = {0}, Table_Schema = {1},
Table_Name = {2}, Table_Type = {3}", _
' rw.Item("TABLE_CATALOG"), rw.Item("TABLE_SCHEMA"), _
' rw.Item("TABLE_NAME"), rw.Item("TABLE_TYPE"))
'sysdiagrams shows up if you have a database diagram;
exclude it here
If rw.Item("TABLE_NAME").ToString.ToUpper <> "SYSDIAGRAMS"
Then
Me.Add(rw.Item("TABLE_NAME").ToString)
End If
Next
'sort the list of tables
Me.Sort()
Catch
MessageBox.Show("Error opening connection to database.")
Finally
cn.Close()
End Try
End Sub
Robin S.