Dim conn As New System.Data.OleDb.OleDbConnection()
        conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb"

        If conn.State = ConnectionState.Open Then conn.Close()
        conn.Open()

        Dim sql As String = "SHOW * From tbl_info Where AdminNo = '" & ListBoxassign.Items & "'"

        listboxassign.items.show(AdminNo)

Recommended Answers

All 7 Replies

There is no Show statement. You need to use the Select statement.

There is no "Show" keyword in SQL Statement to retrieve data from a table.
Your SQL Statement swhould be

Dim sql As String = "Select * From tbl_info"

Now create a command object and dataReader object to read data from that table.

have error

Dim sql As String = "Select * From tbl_info = '" & ListBoxassign.Items & "'"

(Error 1 Operator '&' is not defined for types 'String' and 'System.Windows.Forms.ListBox.ObjectCollection'. )

i waned to show the adminno on the listbox

Please post your codes.

Private Sub ListBoxassign_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBoxassign.SelectedIndexChanged

    Dim conn As New System.Data.OleDb.OleDbConnection()
    conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb"

    If conn.State = ConnectionState.Open Then conn.Close()
    conn.Open()

    Dim sql As String = "Select * From tbl_info where AdminNo"

    Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql, conn)
    sqlCom.Connection = conn

    Dim sqlReader As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader

    While sqlReader.Read = True

        **ListBoxassign = (sqlReader.Item("AdminNo").ToString)**



    End While
    sqlReader.Close()
    sqlCom.Dispose()
    conn.Close()

like this.. i have change but
ListBoxassign = (sqlReader.Item("AdminNo").ToString)

error how to write it

ListBoxassign = (sqlReader.Item("AdminNo").ToString)

It should be

ListBoxassign.Items.Add(sqlReader.Item("AdminNo").ToString)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.