Error when selecting the second data/Listview information

Asked

Viewed 34 times

0

I’m developing a applying and I am stuck in the following process. The application is called "INFORTGEI" and is for a computer store. When we run the application we can observe a form/main window(form/window) with a track menu(stripmenu) in it(a), the stripmenu contains some bhuts(button) that open a Mdiparent or in other words, a new small window inside the form/main window, in the new Mdiparent I have 2 labels(label), with the text(text) equal to "Postal Code" and "Locality". Next to each label we have 2 text boxes(textbox). We also have 4 simple buttons, button add, button edit, button remove and button get out of. Next to everything I’ve said so far, there’s a list display(Listview) and when you select the first datum(date) whatever nothing happens and the data is selected without any error, but when we choose the second data, whatever gives the following error(error):

Erro ocorrido, clique no link para observar!

My teacher and I tried several possibilities to solve the problem, but even my teacher couldn’t identify how to solve it.I’ll leave the code below for anyone who wants to have the opportunity to analyze, who knows if there is a mistake.

Imports System.Data.OleDb

Public Class frmcodigopostal

Dim connection As New OleDbConnection

Private Sub frmcodigopostal_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Try
        connection.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 are the masters at the moment.

  • Resolved issue.

  • Ideally put the answer below and then mark as the solution to help others.

  • As soon as I have availability I will post the reply.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.