question with data binding (noobie question)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • qazplm114477
    New Member
    • Oct 2008
    • 19

    question with data binding (noobie question)

    lets say i have 1 table called Inventory and another table called itemType

    Inventory
    -itemID -PK
    -Desc
    -itemID- FK

    itemType
    -ItemID - PK with relation to inventory.itemI D - FK
    -ItemName

    I have a dataset with these tables and a bindingsource with the inventory table
    I created a form to display both data

    the question is, how do i bind data with itemType to a combo box so it allows me to view the item type for each item and save the changes. I can already save the changes for the inventory, but im having problems with displaying my itemTypeComboBo x properly, im not sure what to put in the
    Data Bound Items> Data source, Display member, Value Member, Selected Item and Selected Value of the comboBox

    Im using Visual Studio 2008 and SQL 2005

    any suggestion would be greatly appreciated, im very new with visual basic so please be easy on me... thanks ^_^
  • TamusJRoyce
    New Member
    • Apr 2008
    • 108

    #2
    From what little experience I have (and that's very little. I'm a c++ programmer, mostly), once you bind your class to the table, the object you bind it to will automatically be changed as you change the table.

    Try not directly manipulating the datasource/bounditem from the table, but instead directly use the object you set bound to that table.

    As an example, you can find what has been selected by comparing "If Table.SelectedR ow.BoundItem Is TheClassThatWas Bound.AnArray(e lementIndex) Then" manipulate TheClassthatWas Bound.AnArray(e lementIndex).

    Poorly worded, but the idea is to only work on the object that is bound (as the source), and never on the Tables DataSource/BoundItem.

    But I've never directly bound data to a combo box, so maybe there is a graphical way to bind the same object to both your table and your combo-box.

    Anyone else have any ideas?

    Comment

    • qazplm114477
      New Member
      • Oct 2008
      • 19

      #3
      Originally posted by TamusJRoyce
      From what little experience I have (and that's very little. I'm a c++ programmer, mostly), once you bind your class to the table, the object you bind it to will automatically be changed as you change the table.

      Try not directly manipulating the datasource/bounditem from the table, but instead directly use the object you set bound to that table.

      As an example, you can find what has been selected by comparing "If Table.SelectedR ow.BoundItem Is TheClassThatWas Bound.AnArray(e lementIndex) Then" manipulate TheClassthatWas Bound.AnArray(e lementIndex).

      Poorly worded, but the idea is to only work on the object that is bound (as the source), and never on the Tables DataSource/BoundItem.

      But I've never directly bound data to a combo box, so maybe there is a graphical way to bind the same object to both your table and your combo-box.

      Anyone else have any ideas?
      Thanks, I'm still trying to understand databases. I found some videos on msdn that teaches how to bind data to an object graphically. it would be great to understand how to bind data through coding but im not quite there yet ^_^. But you're right, the data does change automatically when I change the table... im still trying to figure out how to prevent that. ^^

      Thanks for the advice

      Comment

      • OuTCasT
        Contributor
        • Jan 2008
        • 374

        #4
        Originally posted by qazplm114477
        Thanks, I'm still trying to understand databases. I found some videos on msdn that teaches how to bind data to an object graphically. it would be great to understand how to bind data through coding but im not quite there yet ^_^. But you're right, the data does change automatically when I change the table... im still trying to figure out how to prevent that. ^^

        Thanks for the advice
        This is how i bind items dynamically.

        Create ur connectionstrin g
        Create ur SqlDataAdapter
        and fill is with your SqlCommand

        [CODE=sql]Dim sqlCon As SqlConnection = New SqlConnection([connectionStrin g])

        'Commands and adapter for the Employee masterfile
        Dim sqlEmployeeComm and As SqlCommand
        Dim sqlEmployeeAdap ter As SqlDataAdapter
        Dim sqlEmployeeData Table As DataTable

        'Currency Managers for Commands above
        Dim sqlEmployeeMana ger As CurrencyManager

        sqlEmployeeComm and = New SqlCommand([SELECT STATEMENT)sqlCo nnection)
        sqlEmployeeAdap ter = New SqlDataAdapter( sqlEmployeeComm and)
        sqlEmployeeData Table = New DataTable
        sqlEmployeeAdap ter.Fill(sqlEmp loyeeDataTable)

        label1.databind ings.add("text" ,sqlEmployeeDat aTable, "[ColumnName]", true)[/CODE]

        and u bind it so on etc.
        Remember to create a currency manager to be able to navigate through the records and create one if you want to save.

        [CODE=sql]sqlEmployeeMana ger = DirectCast(Me.B indingContext(s qlEmployeeDataT able), CurrencyManager )[/CODE]


        If you want to save this is what you do.


        [CODE=sql]sqlEmployeeMana ger.EndCurrentE dit()
        sqlConnection.O pen()

        Dim sqlEmployeeUpda te As New SqlCommandBuild er(sqlEmployeeA dapter)
        Try
        sqlEmployeeAdap ter.Update(sqlE mployeeDataTabl e)

        Catch sqlExc As SqlException
        MsgBox(sqlExc)
        End Try

        sqlConnection.C lose()[/CODE]

        Comment

        Working...