I have a text box which I search SQL server which returns to values based on the text I pass the SP and then I want to add to the list box items so here is my code below
the DataTable contains the item I want to return in the list, I have used this syntax to populate a Datagrid with no problems, but I can`t seem to add the item in the listbox can anyone help thanks

Dim SPName As SqlCommand
        Dim DbAdapter As New SqlDataAdapter
        Dim DTptntData As New DataTable


        SPName = New SqlCommand("myDB.dbo.Get_Coders_ICD10", EcnConn) 'running a stored procedure
        SPName.CommandType = CommandType.StoredProcedure




        Dim Param1 As SqlParameter = SPName.Parameters.Add("@ICDCode", SqlDbType.Char, 5)
        Param1.Value = txtICD.Text.Trim


        Try

            SPName.Connection.Open()
            SPName.CommandTimeout = 0
            DbAdapter = New SqlDataAdapter(SPName)
            DbAdapter.Fill(DTptntData)
            lstDiag.Items.Add(DTptntData)
           

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        SPName.Dispose()
        EcnConn.Close()

Recommended Answers

All 2 Replies

does it return an error?

I fixed it myself thanks anyway I added the below line

lstDiag.Items.Add(DTptntData.Rows(0).Item(0) & "-" & DTptntData.Rows(0).Item(1))

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.