Hello

How I can retrive table names from SqlData base

I Just connect to DB. and now I want to display all tables name in combobox.
how I can do that??

thanks

Hello

How I can retrive table names from SqlData base

I Just connect to DB. and now I want to display all tables name in combobox.
how I can do that??

thanks

hey dude - You can use either sysobjects or information_schema.Tables of sql server to retrieve the table name from a specific database. the query will look like below
1) Select name, id from SysObjects where xtype = 'u' and name <> 'dtproperties' order by name asc
2) Select * from Information_Schema.Tables where table_type = 'base table' and table_name <> 'dtproperties'

use this query in SqlDataAdapter, then fill the data table using Fill() method of SqlDataAdapter. Now bind your combo box with data table.

I hope it will work you.

DBCommand = New SqlDataAdapter _
("Select * from Information_Schema.Tables where table_type = 'base table' and table_name <> 'dtproperties'", sqlConn)
DBCommand.Fill(datatable1)
DropDownList1.DataSource = datatable1
DropDownList1.DataBind()

I do what you see ??
but the combobox filled by (system.data.row) just ??

start quote:

DBCommand = New SqlDataAdapter _
("Select * from Information_Schema.Tables where table_type = 'base table' and table_name <> 'dtproperties'", sqlConn)
DBCommand.Fill(datatable1)
DropDownList1.DataSource = datatable1
DropDownList1.DataBind()

I do what you see ??
but the combobox filled by (system.data.row) just ??

explain in detail please ... i can't get what you are trying to say ? is there any issue in the query i have sent ?

dropdownlist items filled by this sentence (system.data.dataRowView)
the table name doesn't appear

dropdownlist items filled by this sentence (system.data.dataRowView)
the table name doesn't appear

oh...you need to set the DataTextField of your drop down with the column name you want to show in dropdown.

here in your case it should be "table_name" column.

so your code looks like
DropDownList1.DataSource = datatable1
DropDownList1.DataTextField = "table_name"
DropDownList1.DataBind()

thanks
it works.
^_^

thanks
it works.
^_^

cool :-)...can you please mark it as solved ?

Imports System.data.sqlclient
Imports system.data

dim objcon as new sqlconnection
dim dt as new datatable

dim str as string = " DataBase Path "

If objcon.state = connectionstate.closed()
objcon.connectionstring = str
objcon.open()
end if

dim query as string="select * from infomation_schema.tables"
dim da as new sqldataadapter(query,objcon)
da.fill(dt)

dropdownlist1.datasource = dt
dropdownlist1..datatextfield = "table_name"
dropdownlist1..databind()

objcon.close()

also you can use code below to connect to your database

"data source=.\sqlexpress;attachdbfilename=|datadirectory|\database.mdf;_
integrated security=true;user instance=true;"

RED Desc : use your DataBase name

KOUROSH NIKZAD

could you help me in doing this using oracle???????

try this...

select * from sys.tables where name = 'tablename'
select * from sys.procedure where name = 'Spname'
select * from sys.databases where name = 'DBname'
select * from sys.Views where name = 'Viewname'

I have 2 database each contain 1 table. I want to import the database into the grid using Openfiledialogue, if i select database 1 means the grid shows database 1 table value, if i select database 2 means the same grid display the database 2 table value. how can i do that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.