Error when selecting second data / ListView information

0

I'm developing an application and I'm stuck in the following process. The application is called "INFORTGEI" and is for a IT shop . When we run the application we are able to observe a form / window ) with a stripmenu menu) strong> in it, the stripmenu contains some button ) that open a MDIparent or in other words a new small window inside form / main window, in the new MDIparent I have 2 labels ) , with text ) to "Postal Code" and "Location". Next to each label we have 2 text boxes ) . We also have 4 simple buttons, add button, edit button, remove button and exit button. Next to everything I've said so far, there is a ListView ) and when you select the first given date) :

MyteacherandItriedseveralpossibilitiestosolvetheproblem,butmyteachercouldnotidentifyhowtosolveit.I'llleavethecodebelowforanyonewhowantstohavetheopportunitytoanalyze,whoknowstheerror.

ImportsSystem.Data.OleDbPublicClassfrmcodigopostalDimconnectionAsNewOleDbConnectionPrivateSubfrmcodigopostal_Load(senderAsObject,eAsEventArgs)HandlesMyBase.LoadTryconnection.ConnectionString="provider = microsoft.jet.oledb.4.0;data source=..\INFORTGEI.mdb"
        connection.Open()
        connection.Close()
    Catch ex As Exception
    End Try

    listacodigopostal()
End Sub

Private Sub addbutton_Click(sender As Object, e As EventArgs) Handles addbutton.Click
    Dim ds As New DataSet
    Dim dt As New DataTable
    ds.Tables.Add(dt)

    Dim da As New OleDbDataAdapter("INSERT INTO CODIGO_POSTAL (CODIGO_POSTAL, LOCALIDADE) values ('" & txtcod_postal.Text & "','" & txtlocalidade.Text & "')", connection)

    da.Fill(dt)

    limpacampos()
    listacodigopostal()
End Sub

Private Sub removebutton_Click(sender As Object, e As EventArgs) Handles removebutton.Click
    Dim ds As New DataSet
    Dim dt As New DataTable
    ds.Tables.Add(dt)

    Dim da As New OleDbDataAdapter("DELETE * FROM CODIGO_POSTAL WHERE CODIGO_POSTAL LIKE('" & txtcod_postal.Text & "')", connection)

    da.Fill(dt)

    limpacampos()
    listacodigopostal()
End Sub

Private Sub editbutton_Click(sender As Object, e As EventArgs) Handles editbutton.Click
    Dim ds As New DataSet
    Dim dt As New DataTable
    ds.Tables.Add(dt)

    Dim da As New OleDbDataAdapter("UPDATE CODIGO_POSTAL SET LOCALIDADE = '" & txtlocalidade.Text & "' WHERE CODIGO_POSTAL = '" & txtcod_postal.Text & "'", connection)

    da.Fill(dt)

    limpacampos()
    listacodigopostal()
End Sub

Private Sub exitbutton_Click(sender As Object, e As EventArgs) Handles exitbutton.Click
    Close()
End Sub

Private Sub listacodigopostal()
    Dim dt As New DataTable
    Dim ds As New DataSet
    ds.Tables.Add(dt)
    Dim da As New OleDbDataAdapter("SELECT * FROM CODIGO_POSTAL", connection)
    da.Fill(dt)
    Dim coluna As DataRow
    For Each coluna In dt.Rows
        listacp.Items.Add(coluna.Item(0))
        listacp.Items(listacp.Items.Count - 1).SubItems.Add(coluna.Item(1))
    Next
End Sub

Private Sub Listar_Dados()
    txtcod_postal.Text = listacp.SelectedItems.Item(0).SubItems(0).Text
    txtlocalidade.Text = listacp.SelectedItems.Item(0).SubItems(1).Text
End Sub

Private Sub listacp_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listacp.SelectedIndexChanged
    Listar_Dados()
End Sub

Private Sub limpacampos()
    txtcod_postal.Text = ""
    txtlocalidade.Text = ""
End Sub

End Class

With this I hope to have explained everything correctly and any questions that may arise, please feel free to clarify and help those who want to help solve my problem. After all, you who are the masters of the moment.

    
asked by anonymous 05.01.2017 / 14:40

0 answers