|
-
Feb 23rd, 2003, 08:30 PM
#1
Thread Starter
Sleep mode
populate combobox with tables from db[Resolved by Edneeis]
ummm , How can I populate combobox with tables from dataset(all tables in db) ??
Last edited by Pirate; Feb 23rd, 2003 at 11:10 PM.
-
Feb 23rd, 2003, 08:50 PM
#2
Thread Starter
Sleep mode
I searched the forum with no luck all seem to talk about populating columns and fields .
-
Feb 23rd, 2003, 10:15 PM
#3
Thread Starter
Sleep mode
I don't want to use Bindings by the way .
thanx
-
Feb 23rd, 2003, 10:18 PM
#4
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"
-
Feb 23rd, 2003, 11:09 PM
#5
Thread Starter
Sleep mode
Thanx Ed .It's working like a charm !
-
Feb 23rd, 2003, 11:34 PM
#6
Thread Starter
Sleep mode
Which is better , data binding or throuh code (I like coding these stuff but I just wonder )
-
Feb 24th, 2003, 12:54 AM
#7
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.
-
Feb 24th, 2003, 12:59 AM
#8
Thread Starter
Sleep mode
can that be set at runtime ??
-
Feb 24th, 2003, 01:05 AM
#9
Thread Starter
Sleep mode
another question : Is it automatically updated ??
silly question :Isn't for small projs?
thanx
-
Feb 24th, 2003, 01:20 AM
#10
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.
-
Feb 24th, 2003, 01:23 AM
#11
Thread Starter
Sleep mode
I mean if I created a new table in the db , can it be automaticaly added to the db ?
-
Feb 24th, 2003, 02:33 AM
#12
Thread Starter
Sleep mode
Just forget it Edneeis . Coding ado.net is acceptable pain .
thanx for your great help !
-
Feb 24th, 2003, 02:35 AM
#13
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.
-
Feb 24th, 2003, 02:37 AM
#14
Thread Starter
Sleep mode
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.
exactly !
-
Feb 24th, 2003, 02:40 AM
#15
Thread Starter
Sleep mode
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?
-
Feb 24th, 2003, 02:45 AM
#16
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.
-
Feb 24th, 2003, 02:49 AM
#17
Thread Starter
Sleep mode
-
Feb 24th, 2003, 02:58 AM
#18
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.
Last edited by Edneeis; Feb 24th, 2003 at 03:01 AM.
-
Feb 24th, 2003, 01:29 PM
#19
Thread Starter
Sleep mode
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 think I have to enjoy it anywasy . I will build my own db dll so I can use it without involving into this hell .
I appreciate your input Ed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|