Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i need help with this situation.
I developing a software in VB.NET with mySQL. The code runs well, when i "insert", it updates the database, but when i edit the data nothing happens. here is my save data code, the problem is that i get no errors.

VB
Dim ano, nome, func, nasc, naci, cap, hab, embid As String
            Dim chk As Boolean
            If CheckBox4.Checked = True Then
                chk = True
            ElseIf CheckBox4.Checked = False Then
                chk = False
            End If
            'Me.TripulacaoTableAdapter.FillByNome_emb(Me.UccbarcosegurDataSet4.Tripulacao, TextBox5.Text, Label65.Text)
            If Me.UccbarcosegurDataSet.tripulacao.Count = 1 Then
                embid = Me.DataGridView3.Rows(0).Cells(0).Value.ToString
                ano = Label90.Text
                nome = TextBox5.Text
                func = ComboBox6.SelectedItem.ToString
                nasc = TextBox7.Text
                naci = ComboBox5.SelectedItem.ToString
                cap = TextBox8.Text
                hab = TextBox6.Text
                Me.DataGridView3.Enabled = False
                Try

                    'order, ano, nome, func, nasc, naci, cap, hab, chk.ToString, Label65.Text
                    Me.UccbarcosegurDataSet.tripulacao.Rows(0).Item(2) = nome
                    Me.UccbarcosegurDataSet.tripulacao.Rows(0).Item(3) = func
                    Me.UccbarcosegurDataSet.tripulacao.Rows(0).Item(4) = nasc
                    Me.UccbarcosegurDataSet.tripulacao.Rows(0).Item(5) = naci
                    Me.UccbarcosegurDataSet.tripulacao.Rows(0).Item(6) = cap
                    Me.UccbarcosegurDataSet.tripulacao.Rows(0).Item(7) = hab
                    Me.UccbarcosegurDataSet.tripulacao.Rows(0).Item(8) = chk.ToString
                    Me.UccbarcosegurDataSet.tripulacao.Rows(0).Item(9) = embid
                    Me.UccbarcosegurDataSet.AcceptChanges()
                    Me.TripulacaoTableAdapter.Update(Me.UccbarcosegurDataSet.tripulacao)
                Catch ex As Exception
                    MsgBox(ex, MsgBoxStyle.Critical)
                    Exit Sub
                Finally
                    MsgBox("Tripulante " + nome + " Editado com sucesso", MsgBoxStyle.Information)
                    Me.TripulacaoTableAdapter.FillByIDembarcacao(Me.UccbarcosegurDataSet.tripulacao, Label65.Text)

                    Button6.Enabled = False
                    Button20.Enabled = False
                    Button5.Enabled = True
                    If chk = 1 Then
                        CheckBox4.CheckState = CheckState.Checked
                    Else
                        CheckBox4.CheckState = CheckState.Unchecked
                    End If
                    edt = False
                    Me.DataGridView3.Enabled = True
                    Me.DataGridView3.Refresh()
                End Try
            Else
                MsgBox("Por favor selecione o tripulante a actualizar", MsgBoxStyle.Information)

            End If

this is my update query

SQL
UPDATE       tripulacao
SET                idEmbarcacao = @Param1, Ano = @Param2, Nome = @Param3, Funcao = @Param4, nascido = @Param5, Nacionalidade = @Param6, Capitania = @Param7, Habilitacao = @Param8, activo = @Param9, 
                         EmbarcacaoID = @Param10

this is my insert query

SQL
INSERT INTO tripulacao
                         (idEmbarcacao, Ano, Nome, Funcao, nascido, Nacionalidade, Capitania, Habilitacao, activo, EmbarcacaoID)
VALUES        (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10)


What I have tried:

I, tried rebuilding the update query, but since i get no errors i'm lost
Posted
Updated 9-Mar-18 0:15am
Comments
CHill60 9-Mar-18 6:10am    
Where is the vb code where you set those update parameters?
Demon Slayer 9-Mar-18 6:19am    
first of all, thank you for reply. i update the dataset inside the posted try catch, the problem is that it doesnt updates the data base. i think this is what you asked.
CHill60 9-Mar-18 7:36am    
You have to use the "Reply" link so that people are notified when you reply.
The code you have is updating the Dataset true, but where is your update query called to update the database?
Richard Deeming 9-Mar-18 8:22am    
NB: The code in your Finally block executes every time, regardless of whether or not an exception was thrown.

It's really not the right place to display a "succeeded" message. :)
Demon Slayer 9-Mar-18 9:21am    
Sorry, for the mistake, you 'nailed it. the problem was the missing where clause. After i've added it. works like a charm. Rookie mistake. Thanks for help. you're the best

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900