Results 1 to 19 of 19

Thread: populate combobox with tables from db[Resolved by Edneeis]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Talking 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.

  2. #2

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I searched the forum with no luck all seem to talk about populating columns and fields .

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I don't want to use Bindings by the way .
    thanx

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The trick is using the GetOleDbScemaTable method.
    VB Code:
    1. Dim cnn As New OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=MyServer")
    2.         cnn.Open()
    3.         Dim Tables As DataTable = cnn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
    4.         cnn.Close()
    5.         ListBox1.DataSource = Tables
    6.         ListBox1.DisplayMember = "TABLE_NAME"

  5. #5

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Thanx Ed .It's working like a charm !

  6. #6

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Which is better , data binding or throuh code (I like coding these stuff but I just wonder )

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  8. #8

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    can that be set at runtime ??

  9. #9

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    another question : Is it automatically updated ??
    silly question :Isn't for small projs?
    thanx

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  11. #11

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I mean if I created a new table in the db , can it be automaticaly added to the db ?

  12. #12

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Just forget it Edneeis . Coding ado.net is acceptable pain .
    thanx for your great help !

  13. #13
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  14. #14

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 !

  15. #15

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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?

  16. #16
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  17. #17

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    good logic .I used to love working on db stuff in VB6 not in .NET .
    Thanx a lot for being patient with me

  18. #18
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  19. #19

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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
  •  



Click Here to Expand Forum to Full Width