0

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

7
Contributors
12
Replies
27
Views
7 Years
Discussion Span
Last Post by Karthic_1
0

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.

0
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 ??

Edited by mike_2000_17: Fixed formatting

0

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 ?

Edited by mike_2000_17: Fixed formatting

0

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

Edited by Nada_ward: n/a

0

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()

0

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

Edited by kouroshnik: n/a

0

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'

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.