OK, this will get you the TableNames from an Access Database:
Dim schemaTable as DataTable
Dim connString As String = _
"Data
Source=c:\databasename.mdb;Provider=Microsoft.Jet.OLEDB.4.0;"
' Open the connection.
conn.ConnectionString = connString
conn.Open()
' Populate the DataTable with schema
' information on the data source tables.
schemaTable = _
conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
New Object() {Nothing, Nothing, Nothing, "TABLE"})
' Populate an array with the table names.
i = schemaTable.Rows.Count - 1
Dim tablesArray(i) As String
For i = 0 To schemaTable.Rows.Count - 1
tablesArray(i) = schemaTable.Rows(i).Item("Table_Name")
Next
tablesArray will now contain the TableNames in the database specified in
your connection string:
Then when you get the table name, you can get the columns by doing this:
schemaTable = _
conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, _
New Object() {Nothing, Nothing, _
tableName, Nothing})
' Step through the column names and append
' them into a SELECT statement
i = schemaTable.Rows.Count - 1
Dim columnsArray(i) as String
For x = 0 To schemaTable.Rows.Count - 1
columnsArray(i) =
schemaTable.Rows(x).Item("Column_Name")
Next
columnsArray will now contain the field names from the table in "tableName"
above.
HTH
Ben Miller
----- Original Message -----
From: les_claypoo1
To: [email protected]
Sent: Tuesday, January 04, 2005 8:28 AM
Subject: [AspNetAnyQuestionIsOk] Re: Database table names and asp.net c#
help needed
I am using access databases 97 version I think because it tells me
about converting it when I open it in access 2000. I don't know if
there is any SQL that I can write that will return the table names in
the database. If anybody knows of any or knows how to do it please
let me know.
--- In [email protected], "Ben Miller"
<[EMAIL PROTECTED]> wrote:
> It depends on what database you are using.
>
> If you are using SQL Server then I would use the (select table_name
from information_schema.tables) to get the tables, and then (select
column_name from information_schema.columns where table_name = 'table
selected')
>
> HTH
> Ben Miller
>
>
>
> ----- Original Message -----
> From: les_claypoo1
> To: [email protected]
> Sent: Monday, January 03, 2005 8:52 AM
> Subject: [AspNetAnyQuestionIsOk] Database and asp.net c# help
needed
>
>
>
>
> I am creating a program and I want to have it load a certain
database
> and load its table names into and drop down list. Then I wanted
> them to click on a button and when they did that they would get a
> drop down box with the field names so they can select which
fields
> they would want. From there I know what I want to do but any
help on
> how to load this stuff in would be great. Thanks!
>
>
>
>
>
>
>
>
> --------------------------------------------------------------------
----------
> Yahoo! Groups Links
>
> a.. To visit your group on the web, go to:
> http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
>
> b.. To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]
>
> c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.
>
>
>
> [Non-text portions of this message have been removed]
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/