Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        txtdayattended.Enabled = True
        sql = " select work_day from tbl_yearset where  month='" & ComboBox3.Text & "'"
        If rs.State = 1 Then rs.Close()
        rs.Open(sql, conn)
        If rs.EOF = False Then
            txtworkday.Text = rs(0).Value
        End If
    End Sub

Please let me know how to write this code for an oledb connection????

Here is a sample of code that gets values using an OleDbConnection and a DataReader. AddRow just puts the three values into a new ListView Row

Private Sub btnOleDB_Click(sender As System.Object, e As System.EventArgs) Handles btnOleDB.Click

    ListView1.Items.Clear()

    Dim con As New OleDbConnection("Provider=SQLNCLI10;Server=.\SQLEXPRESS;Database=PUBS;Trusted_Connection=Yes;Connect Timeout=15;")
    Dim cmd As New OleDbCommand

    cmd.Connection = con
    cmd.CommandText = "SELECT au_lname,au_fname,zip FROM authors WHERE au_lname like ?"
    cmd.Parameters.Add("@pan", OleDbType.VarChar).Value = "D%"

    con.Open()
    Dim rdr As OleDbDataReader = cmd.ExecuteReader()

    If rdr.HasRows Then
        Do While rdr.Read
            AddRow(rdr.GetString(0), rdr.GetString(1), rdr.GetString(2))
        Loop
    Else
        MsgBox("no records")
    End If

    rdr.Close()
    con.Close()

End Sub

Private Sub AddRow(lname As String, fname As String, zip As Integer)

    Dim item As New ListViewItem

    item.Text = lname
    item.SubItems.Add(fname)
    item.SubItems.Add(zip)

    ListView1.Items.Add(item)

End Sub

I need to write using combobox, so please let me know how to write this code for an oledb connection.

Edited 4 Years Ago by Neethaa

Try

Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged

    Dim con As New OleDbConnection(put your string here)
    Dim cmd As New OleDbCommand

    cmd.Connection = con
    cmd.CommandText = "select work_day from tbl_yearset where  month='" & ComboBox3.Text & "'"

    con.Open()
    Dim rdr As OleDbDataReader = cmd.ExecuteReader()

    If rdr.HasRows Then
        rdr.Read
        txtworkday.Text = rdr.GetString(0)
    End If

    rdr.Close()
    con.Close()

End Sub
This article has been dead for over six months. Start a new discussion instead.