Jump to content
mihaigrg

eroare vb.net

Recommended Posts

Salut,

 

Cineva care ma poate ajuta cu o solutie la problema de mai jos. Lucrez la o aplicatie in vb.net. Aduc datele dintr-o tabela intr-un datagrid, in care vreau sa editez diverse valori, din diverse celule, dupa care sa le salvez in aceeasi tabela.

Codul este cel de mai jos. Problema este ca-mi da eroare  de mai jos...

 

"NullReferenceException occurrent

A first chance exception of type 'System.NullReferenceException' occurred in .... "

  

 

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Try
            connection.Open()
            sBuilder = New SqlCommandBuilder(sAdapter)
            btnLoad.Enabled = False
            sAdapter.Update(sDataSet)
            sDataSet = Nothing
            btnModify.Enabled = True
            btnLoad.Enabled = True
            btnLoad.PerformClick()
            MessageBox.Show("Information updated", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            connection.Close()
        End Try
    End Sub

 

https://drive.google.com/file/d/1O4rM2UFTmwgFIObgbXakzwSyETrBMpx9/view?usp=sharing

 

Multumesc anticipat!

Link to comment
Share on other sites

In try-catch trebuie sa prinzi exceptiile pe care vrei sa le manipulezi in ordine si doar in ultima instanta cele neasteptate.

 

try {

 

} catch (NullReferenceException ex) {

   //aici iti va returna ca sDataSet == null

} catch (Exception ex) {

 

}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...