Results 1 to 3 of 3

Thread: Combo Box load - Easy

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279

    Combo Box load - Easy

    I have an easy question but no adequate reference material in front of me at the moment. How do I load a combo box with a dataset? Here's my code:

    Dim strSQL As String
    Dim strConn As String
    Dim objDA As SqlClient.SqlDataAdapter
    Dim objDS As New Data.DataSet()
    Dim intCounter As Integer
    Dim strResult As String

    strConn = "Initial Catalog=pubs;Data Source=(local);" _
    & "User ID=sa;password=;"
    strSQL = "My SQL Statement"

    objDA = New SqlClient.SqlDataAdapter(strSQL, strConn)
    objDA.Fill(objDS)

    'I want to load my combo here. How do I access the fields from the dataset?

    Thanks in advance.
    A cynic knows the price of everything but the value of nothing.

  2. #2
    New Member
    Join Date
    Mar 2002
    Posts
    13
    hi,

    i would do it like that way



    Private Sub Connection()

    With con
    .Mode = ADODB.ConnectModeEnum.adModeReadWrite
    .Provider = "microsoft.jet.oledb.4.0"
    .ConnectionString = "data source= yourPath "
    .Open()
    End With

    strSQL = "SELECT * FROM yourTable "
    rs.Open(strSQL, con, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockPessimistic)

    End Sub

    Private Sub Combobox()

    ComboBox1.Items.Add(rs.Fields(1).Value)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Connection()

    Do While Not rs.EOF
    Combobox()
    rs.MoveNext()
    Loop

    rs.Close()
    con.Close()

    End Sub

    Good Luck

  3. #3
    New Member
    Join Date
    Mar 2002
    Posts
    5
    Try this also...........add the code in the specified event of ur form

    (ds is the dataset,i integer)

    For i = 1 To CInt(ds.Tables(0).Rows.Count)
    ComboBox1.Items.Add(ds.Tables(0).Rows(0)(i))
    Next

    Hope it works..
    I tried the code after executing a storedprocedure which returns 3 fields.
    Last edited by Spice; Mar 8th, 2002 at 06:41 AM.

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