combo box that retrieve data from database in windows based application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AishaKhalfan
    New Member
    • Apr 2007
    • 23

    combo box that retrieve data from database in windows based application

    Hi all,

    I have to populate combo box that retrieve data from database in windows based application. I have two tables which are type and CD. Type has type ID and Category. CD has type ID as foreign key. When I will add a new CD, the user interface for user will show combo box to choose the category from combo box and the selected value should be saved as type ID.

    First, I did a quarry in type dataset that will do search by type ID.

    Now, I don’t know how to use this method to populate the category combo box in CD interface.


    Any volunteer to help me.
  • dwadish
    New Member
    • Nov 2006
    • 129

    #2
    i am not clear with your problem. please simplify it.

    i think you want to save a type id from the table which corresponding catagory you are selected from the list.

    plz specify your question.

    try

    Comment

    • AishaKhalfan
      New Member
      • Apr 2007
      • 23

      #3
      Originally posted by dwadish
      i am not clear with your problem. please simplify it.

      i think you want to save a type id from the table which corresponding catagory you are selected from the list.

      plz specify your question.

      try

      i think you want to save a type id from the table which corresponding catagory you are selected from the list.


      This is what I mean. You understand correctly

      Comment

      • dwadish
        New Member
        • Nov 2006
        • 129

        #4
        first bind the category from the type table to combobox.

        select the typeid from the table where catagory= combobox.text
        assign the typeid to a variable.

        insert the typeid(variable ) into cd table.

        try it now

        Comment

        • AishaKhalfan
          New Member
          • Apr 2007
          • 23

          #5
          Hi,


          Could you provide me with example (Code ) for each step, please?

          So that it can be cleared, because someone else has this problem. As a result, all body can benefit.


          Your help is appreciated.


          Thank you & Waiting to answer

          Comment

          • dwadish
            New Member
            • Nov 2006
            • 129

            #6
            Code:
               USERDISPFORM_ LOAD()
             OPEN THE DB CONECTION
            
              DIM DS AS NEW DATASET
            DIM adpt as New sqldataadapter("select catagory from type",con)
            adpt.fill(dt)
            
            combo1.datasource=dt.tables(0)
            combo1.displaymember="catagory"
            
            close connection
            end sub
            
             select any  event you like
            
                           button1_clik( )
            open connection
            
            dim cmd as new sqlcommand("select typeid from type where catagory='"& combo1.text &"' ",con)
            
            dim dr as sqldatareader
            dr=cmd.exicutereader
            dim s as string
            while dr.read
            s=dr.getvalue(0)
            end while
            
            dr.close
            dim cmd2 as new sqlcommand("insert into cd values('"& s &"')",con)
            dim dr as sqldatareader
            dr=cmd2.exicutenonquery
            dr.close
            close connection
            try it now

            Comment

            • AishaKhalfan
              New Member
              • Apr 2007
              • 23

              #7
              Originally posted by dwadish
              Code:
                 USERDISPFORM_ LOAD()
               OPEN THE DB CONECTION
              
                DIM DS AS NEW DATASET
              DIM adpt as New sqldataadapter("select catagory from type",con)
              adpt.fill(dt)
              
              combo1.datasource=dt.tables(0)
              combo1.displaymember="catagory"
              
              close connection
              end sub
              
               select any  event you like
              
                             button1_clik( )
              open connection
              
              dim cmd as new sqlcommand("select typeid from type where catagory='"& combo1.text &"' ",con)
              
              dim dr as sqldatareader
              dr=cmd.exicutereader
              dim s as string
              while dr.read
              s=dr.getvalue(0)
              end while
              
              dr.close
              dim cmd2 as new sqlcommand("insert into cd values('"& s &"')",con)
              dim dr as sqldatareader
              dr=cmd2.exicutenonquery
              dr.close
              close connection
              try it now


              Hi,


              Thank you a lot Mr. dwadish for hepling and its works

              This is because, you helped me a lot to over come this problem which stop me to complete my project.


              Wish you a good luck.



              Aisha

              Comment

              • dwadish
                New Member
                • Nov 2006
                • 129

                #8
                Welcome !! Aisha

                which project you are doing. or for what

                Comment

                • AishaKhalfan
                  New Member
                  • Apr 2007
                  • 23

                  #9
                  Originally posted by dwadish
                  Welcome !! Aisha

                  which project you are doing. or for what

                  it's for company friend.

                  Comment

                  • dwadish
                    New Member
                    • Nov 2006
                    • 129

                    #10
                    sorry best of luck.

                    i am a student of mcsd.net .

                    =============== =============== =

                    Comment

                    • AishaKhalfan
                      New Member
                      • Apr 2007
                      • 23

                      #11
                      Originally posted by dwadish
                      sorry best of luck.

                      i am a student of mcsd.net .

                      =============== =============== =

                      Thank you


                      I wish you a good luck toooooooo

                      Comment

                      • dwadish
                        New Member
                        • Nov 2006
                        • 129

                        #12
                        Originally posted by AishaKhalfan
                        Thank you


                        I wish you a good luck toooooooo
                        now i am MCAD.NET

                        Thanx

                        Comment

                        Working...