How to give an SQL statement in combobox(Visual basic 6.0)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sivadhanekula
    New Member
    • Nov 2008
    • 58

    How to give an SQL statement in combobox(Visual basic 6.0)

    Hi everyone..

    I want to insert a combobox with the list of test names of a database, but the testname contains 15000+ data, and I cant type all the data. so can any one help me in writing an SQL statement, so that if I give that statement it will automatically swaps the table names to the combobox.

    P.S I know the SQL statement but I dono where to give that SQL statement in combobox

    explanation with program will be verymuch helpfull for me

    Thanks in advance

    Regards
    Siva
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    you just need to go 1...2...3

    1.Create a connection
    2. open the recordset
    3. in a loop add the items from recordset to combobox.

    Comment

    • sivadhanekula
      New Member
      • Nov 2008
      • 58

      #3
      haaa....I am totally new to Visual basic....I am not able to understand what you are telling...can you explain in detail...plzz.. .I have done some program to extract the data...in the program if you look at the SQL statement(under lined) I want to insert all the values of fullname into the combo box, so that if I select one of the fullname then the data regarding that fullname should be extracted and should be displayed after pressing the Ok button

      Private Sub Okbutton_Click( )
      On Error Resume Next

      Dim sConnect As String
      Dim db As Database
      Dim rs As Recordset
      Dim Ws As Workspace
      'Dim ID As Double
      'Dim doubleID1 As Double
      Dim intstring As String

      Set Ws = DBEngine.Worksp aces(0)

      sConnect = "ODBC;DSN=WinUT MS_RT_DB;UID=Lo calhost;PWD=;Da tabase=WinUTMS_ RT_DB;"

      Set db = Ws.OpenDatabase ("", 0, 0, sConnect)

      Set rs = db.OpenRecordse t("SELECT Fullname FROM abssubtest")
      Do While Not rs.EOF
      'ID = rs!Messwert
      'doubleID1 = rs!UPLimWert
      intstring = rs.Fields("Full name")
      rs.MoveNext
      Loop
      End Sub

      Comment

      • EYE4U
        Banned
        New Member
        • Oct 2008
        • 76

        #4
        I have made some changes to your loop....

        Code:
        Do While Not rs.EOF
        'ID = rs!Messwert
        'doubleID1 = rs!UPLimWert
        combo1.add (rs.Fields("Fullname"))
        rs.MoveNext
        Loop
        End Sub
        Regards
        ARUZ

        Comment

        • sivadhanekula
          New Member
          • Nov 2008
          • 58

          #5
          Private Sub Combo1_Click()

          Label1.Caption = "find" & Combo1.Text
          Label1.Visible = True

          End Sub

          Private Sub Form_Load()
          On Error Resume Next

          Label1.Visible = False
          DataGrid1.Visis ble = False

          Dim cn As ADODB.Connectio n
          Dim rs As ADODB.Recordset

          Set cn = New ADODB.Connectio n
          cn.ConnectionSt ring = "ODBC;DSN=WinUT MS_RT_DB;UID=Lo calhost;PWD=;Da tabas e=WinUTMS_RT_DB ;"
          cn.Open

          Set rs = New ADODB.Recordset
          rs.Open "absprfg", cn, adOpenKeyset, adLockPessimist ic, adCmdTable

          Do While Not rs.EOF
          Combo1.AddItem rs.Fields("Modu s")
          rs.MoveNext
          Loop
          If Not (rs.EOF And rs.BOF) Then
          rs.MoveFirst
          End If
          End Sub
          Private Sub Command1_Click( )
          On Error Resume Next
          Me.Form.RecordS ource = "SELECT Fullname FROM abssubtest & ComboBox.Value & " ';"

          Me.Requery
          End Sub

          Private Sub Label1_Click()
          DataGrid1.Visib le = True

          Adodc1.CommandT ype = adCmdText
          Adodc1.RecordSo urce = "select absprfg.Modus From absprfg WHERE absprfg.Modus=' " & Combo1.Text & "' "
          Adodc1.Refresh

          End Sub
          I have done the above program..but after pressing the run button..I am getting the blank screen and after some time the vb is not responding and I have to close the program...even I have seen it with break point but of no use....can you please tell me where I have done the mistake...

          Regards
          Siva

          Comment

          • EYE4U
            Banned
            New Member
            • Oct 2008
            • 76

            #6
            I think at this line your are having problem.
            Code:
            Me.Form.RecordSource = "SELECT Fullname FROM abssubtest & ComboBox.Value & " ';"

            Comment

            Working...