freelanceprogrammers.org Forum Index » ASP

Re: Database table names and asp.net c# help needed


View user's profile Post To page top
ben4miller Posted: Wed Jan 05, 2005 3:09 am


Joined: 05 Jan 2005

Posts: 3
Re: Database table names and asp.net c# help needed
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: AspNetAnyQuestionIsOk@yahoogroups.com
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 AspNetAnyQuestionIsOk@yahoogroups.com, "Ben Miller"
<mylists@b...> 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: AspNetAnyQuestionIsOk@yahoogroups.com
> 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:
> AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com
>
> 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:
AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Reply with quote
Send private message
View user's profile Post To page top
les_claypoo1 Posted: Wed Jan 05, 2005 11:43 pm


Joined: 05 Jan 2005

Posts: 6
Re: Database table names and asp.net c# help needed
Ben Miller I just wanted to say YOU ROCK. The code I used was a
little different because I am using C#, but it got me going in the
right direction. Thanks for the help and keep up the good work.

-Tom

--- In AspNetAnyQuestionIsOk@yahoogroups.com, "Ben Miller"
<mylists@b...> wrote:
> 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: AspNetAnyQuestionIsOk@yahoogroups.com
> 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 AspNetAnyQuestionIsOk@yahoogroups.com, "Ben Miller"
> <mylists@b...> 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: AspNetAnyQuestionIsOk@yahoogroups.com
> > 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:
> > AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com
> >
> > 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:
> AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help