mihaigrg Posted August 28, 2019 Report Posted August 28, 2019 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! Quote
mihaigrg Posted August 28, 2019 Author Report Posted August 28, 2019 47 minutes ago, gigiRoman said: Ai initializat conexiunea? Da. Problema cred ca apare dincauza filtrelor. Afisarea in datagrid se face in urma unor filtre. Daca afisez toate datele din tabele, modific si salvez... merge. Daca aplic filtrele si incerc, nu mai merge. Quote
Erase Posted August 28, 2019 Report Posted August 28, 2019 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) { } Quote