0

Hi

I want to add the table names from a database in sql server to a combobox with vb.net windows programming.

Its a customer accounts database where for instance I add a new Account holder which creates a new Table and when I want to view a specific account holder a want to select that account holder from a combobox that views the Table names.

Im completely lost about this and if anyone can help me would be great.

Thanks
Hannes

3
Contributors
2
Replies
7
Views
7 Years
Discussion Span
Last Post by kouroshnik
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

This topic has been dead for over six months. 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.