Please help me for my syntax error?

and I want to show all the First Middle and Last Name in the listbox i.e.
into Listbox
First Middle Last
Amit Anoop Motwani

Edited 6 Years Ago by WaltP: Do not post help requests as CODE SNIPPETS.

Well how can we help you with your syntax error if you do not post the relavent code???????

Use the AddItem method...

Good Luck

Well how can we help you with your syntax error if you do not post the relavent code???????

Use the AddItem method...

Good Luck

The following code is load in Page load event

Private Sub PopulateProductList()
        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader
        Dim strSQL As String
        Dim objListItem As ListItem

        Try
            strSQL = "SELECT [Sr No], [First Name] FROM [Lani]"

            con = New OleDbConnection(connectionString)
            con.Open()

            cmd = New OleDbCommand(strSQL, con)
            dr = cmd.ExecuteReader()

            lblani.Items.Clear()
        
            Do While dr.Read()
                objListItem = New ListItem(dr.Item("First Name").ToString(), _
                                           CInt(dr.Item("Sr No")))
                lblani.Items.Add(objListItem)
            Loop
            If lblani.Items.Count > 0 Then
                lblani.SetSelected(0, True)
            End If

            ' Close and Clean up objects
            dr.Close()
            con.Close()
            cmd.Dispose()
            con.Dispose()

        Catch ex As OleDbException
            MsgBox(ex.Message.ToString)
        End Try

And the following sub routine is load in the Listbox_selectedindexchanged event

Private Sub PopulateForm()
        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader
        Dim strSQL As String
        Dim objListItem As ListItem
        ' Dim strID As String

        Try

            objListItem = CType(lblani.SelectedItem, ListItem)

            strSQL = ("Select * from [Lani] Where [Sr No] = " & txtid.Text)
            con = New OleDbConnection(connectionString)
            con.Open()

            cmd = New OleDbCommand(strSQL, con)
            dr = cmd.ExecuteReader()

            If dr.Read() Then
                ' Populate form with the data in textbox
                txtid.Text = dr.Item("Sr No").ToString()
                txtfirst.Text() = dr.Item("First Name").ToString()
                txtmiddle.Text() = dr.Item("Middle Name").ToString()
                txtlast.Text() = dr.Item("Last Name").ToString()
                txtcomp.Text() = dr.Item("Company Name").ToString()
                
            End If

            ' Close and Clean up objects
            dr.Close()
            con.Close()
            cmd.Dispose()
            con.Dispose()


        Catch e As Exception
            MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")
        End Try

    End Sub


    End Sub

And listitem class

Public Class ListItem
    Private mValue As String   ' Stores a named description of the item
    Private mID As Integer     ' Stores a primary key to the record

    Public Sub New(ByVal strValue As String, ByVal intID As Integer)
        mValue = strValue
        mID = intID
    End Sub

    Public Sub New()
        mValue = ""
        mID = 0
    End Sub

    Property ID() As Integer
        Get
            Return mID
        End Get
        Set(ByVal Value As Integer)
            mID = Value
        End Set
    End Property

    Property Value() As String
        Get
            Return mValue
        End Get
        Set(ByVal Value As String)
            mValue = Value
        End Set
    End Property

      Public Overrides Function ToString() As String
        Return mValue
    End Function
End Class

And subsequently I want to Design the select query by adding the three column i.e. First Name, Middle Name and Last Name in the Listbox and by selecting the list item that will show in text box.


Thanks in advance for helping me.

Edited 6 Years Ago by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

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