Results 1 to 7 of 7

Thread: Fill from dataset

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    124

    Fill from dataset

    I have a combo box being loaded with the 'id' field from my database. (id is autonumber prim key)

    I'm displaying the data in the db with textboxes linked to columns of my db

    When i select a diff id from the combobox i want the data in the textboxes to change accordingly.

    i think this is the correct sql string, but other than that i dont have a thing

    mySQL = "SELECT * FROM Bottle WHERE id = " & cbID.selectedItem

    anything at all would be great

    thx

    db

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If you have already filled a dataset with all the customer info then you can just use databinding to link the different textboxes and what not to the dataset and it will change automatically. Just set the datasource properties on the combo and textboxes to the same dataset.

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by Edneeis
    Just set the datasource properties on the combo and textboxes to the same dataset.
    Not only the same dataset but also using exactly the same objects. If your dataset is myds and the table in it is myTable and you have the fileds 'id' and 'name' in that table then your binding may be like this:

    For the textbox:
    TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", myDs, "mytable.name"))

    and for the combobox:
    Combobox1.Datasource=myds
    Combobox1.DisplayMember="mytable.ID"

    if the objects you are binding not be the same, for example you use
    Combobox1.Datasource=myds.mytable
    Combobox1.DisplayMember="ID"

    the combo still shows the id but changing it wont change the text in the textbox.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    124
    k, i have about 15 textboxes that must be filled
    so for each one do i add the following

    TextBoxXX.DataBindings.Add(New System.Windows.Forms.Binding("Text", myDs, "mytable.CorrespondingColumn"))

    What do i put the "Text" as?

    all the textboxes are already bound to their appropriate columns of the table

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    If you have already bound the text property in designer then that piece of code is automatically genereated, look at the wizard generated code.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    124
    So I just have to bind the combo box to the id column of the table then??

    But when i select a different combobox value, the rest of the fields dont change. How do i bind the combobox so that when i change it's value, the rest of the values also change?

    Is this possible, or do i have to do a search of the table and equate the value of the combobox to the id column?

    db

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    If you read my previous post carefully, i have answered your question there. When working with designer just set the datasource of your combobox to the dataset, let say myds, and its displaymember property to mytable.ID.
    I think you have set the datasource to myds.mytable and displaymember to ID.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

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