ummm , How can I populate combobox with tables from dataset(all tables in db) ??:D
Printable View
ummm , How can I populate combobox with tables from dataset(all tables in db) ??:D
I searched the forum with no luck all seem to talk about populating columns and fields .:(
I don't want to use Bindings by the way .
thanx
The trick is using the GetOleDbScemaTable method.
VB Code:
Dim cnn As New OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=MyServer") cnn.Open() Dim Tables As DataTable = cnn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"}) cnn.Close() ListBox1.DataSource = Tables ListBox1.DisplayMember = "TABLE_NAME"
Thanx Ed .It's working like a charm !:)
Which is better , data binding or throuh code (I like coding these stuff but I just wonder )
IN VB6 I never liked databinding, but in .NET I do use it for non complex items like filling lists and things like that but I don't let it handle the adding of new data (although that is just me). Although I also bind to classes a lot instead of the data directly. One thing I've noticed with Listboxes and Combos is they fill faster with databinding then with the addrange method.
can that be set at runtime ??
another question : Is it automatically updated ??
silly question :D :Isn't for small projs?
thanx
Can what be set at runtime? And does what update automatically?
If you mean does databinding update then for the most part I believe so. There are some issues with things like binding Arraylists to Datagrid or misc things like that but there are definately work arounds for the problems that exist and other datasources work right.
I mean if I created a new table in the db , can it be automaticaly added to the db ?
Just forget it Edneeis . Coding ado.net is acceptable pain .
thanx for your great help !
:)
You mean would it show up in the list? I'm not sure. If it was a new row in a table it should but I think the GetOleDbSchemaTable method just gets the tables at the time you run it.
exactly !Quote:
Originally posted by Edneeis
You mean would it show up in the list? I'm not sure. If it was a new row in a table it should but I think the GetOleDbSchemaTable method just gets the tables at the time you run it.
ummm another question just thought about it ,
Isn't listbox connected to the dataset at runtime. Shouldn't this situation throw error if the user added new table or column etc?
Why would it give an error?
You are binding to a table of data that is the tablenames. It doesn't 'stay' connected to the database though. So it doesn't even know if a new table is added, but if it did it still shouldn't give an error.
See this method basically just looks up the table names and related data at the time its called and dumps it into a datatable object, but it doesn't maintain an connection after that. It just pushes out the data and is done.
good logic :D .I used to love working on db stuff in VB6 not in .NET:confused: .
Thanx a lot for being patient with me:D
I think as you get more familiar with the way .NET uses data you'll like it. It just takes some getting used to. Most of the time in VB6 I worked with disconnected recordsets so the switch to .NETs disconnected way is no big thing.
Also the disconnected nature of this method is not the norm. If you had just a regular table of data and were adding to it in the same app then it would be reflected in the bound list or whatever is binding to the datasource. Thats kind of the whole point of databinding to have it automatically update with changes.
I suppose you could add names to the datatable of database tablenames but that wouldn't actually add tables doing it that way.
I think I have to enjoy it anywasy . I will build my own db dll so I can use it without involving into this hell .:DQuote:
Originally posted by Edneeis
I think as you get more familiar with the way .NET uses data you'll like it. It just takes some getting used to. Most of the time in VB6 I worked with disconnected recordsets so the switch to .NETs disconnected way is no big thing.
Also the disconnected nature of this method is not the norm. If you had just a regular table of data and were adding to it in the same app then it would be reflected in the bound list or whatever is binding to the datasource. Thats kind of the whole point of databinding to have it automatically update with changes.
I suppose you could add names to the datatable of database tablenames but that wouldn't actually add tables doing it that way.
I appreciate your input Ed:)