1

Why do I have this this error? - "Object reference not set to an instance of an object?" This is application which connects to the SubiektGT database. Subiekt is a sales system. I know there is so many topics like this but I can't find a solution for thais one.

Here is my code:

Public Class SubiektGT

    Dim gt As New InsERT.GT
    Dim daneKlienta As New SklepPobieranieDanych  

    'Connection to Subiekt database
    Function UruchomSubiekta() As InsERT.Subiekt

        Dim oSgt As InsERT.Subiekt

        Try
            gt.Produkt = InsERT.ProduktEnum.gtaProduktSubiekt
            gt.Serwer = "USER-KOMPUTER\insertgt"
            gt.Baza = "Sklep"
            gt.Autentykacja = InsERT.AutentykacjaEnum.gtaAutentykacjaMieszana
            gt.Uzytkownik = ""
            gt.UzytkownikHaslo = ""
            gt.Operator = "Szef"
            gt.OperatorHaslo = ""

            oSgt = gt.Uruchom(InsERT.UruchomDopasujEnum.gtaUruchomDopasuj, InsERT.UruchomEnum.gtaUruchomWTle)

        Catch ex As Exception
            MessageBox.Show("Błąd: " & ex.Message)
        End Try    
    End Function


    Private Sub btnDodajKlientaDoSubiekta_Click(sender As Object, e As EventArgs) Handles btnDodajKlientaDoSubiekta.Click    
        daneKlienta.PobierzDaneKlientaDlaSubiekt()
        DodajKontrahenta()   
    End Sub

End Class

Here is the code which throws that exception:

Public Sub DodajKontrahenta()

            Dim oSgt As InsERT.Subiekt
            Dim oKh As InsERT.Kontrahent

            oSgt = UruchomSubiekta()

            oKh = oSgt.Kontrahenci.Dodaj  'EXCEPTION
            oKh.Typ = InsERT.KontrahentTypEnum.gtaKontrahentTypDostOdb

            oKh.Nazwa = daneKlienta.Nazwa
            oKh.NazwaPelna = daneKlienta.Nazwa
            oKh.Miejscowosc = daneKlienta.Miejscowosc
            oKh.Ulica = daneKlienta.Adres
            oKh.Email = daneKlienta.Email

            oKh.Zapisz()
            oKh.Zamknij()
        End Sub

InsERT.Kontrahent is an interface and when the exception comes I try to create a new object. A really don't know why.

XardasLord
  • 1,764
  • 2
  • 20
  • 45

0 Answers0