views:

68

answers:

2

Hi everyone, got a problem here. Hope you can help :D

The software I'm creating manage simple movies information, this form in particoular should edit the data of a given movie. Through the code below, a form is populated with the data gathered from the DB. ("cinema" is a Dataset gloablly declared).

public short popolaModificaFilm(string titolo, ref TextBox txtAnno, ref TextBox txtCast, ref TextBox txtDurata, ref TextBox txtLocandina, ref TextBox txtRegista, ref TextBox txtTitolo, ref TextBox txtTrailer, ref TextBox txtTrama, ref ComboBox cmbGenere, ref ComboBox cmbNaz, ref CheckBox chkPellicola, ref CheckBox chkDigitale, ref CheckBox chk3d)
    {
        service.ricercaFilm(titolo).CopyToDataTable(cinema.film, LoadOption.PreserveChanges);
        dsCinema.filmRow film = cinema.film[0];
        txtAnno.Text = film["anno"].ToString().Trim();
        txtCast.Text = film["cast"].ToString().Trim();
        txtDurata.Text = film["durata"].ToString().Trim();
        txtLocandina.Text = film["locandina"].ToString().Trim();
        txtRegista.Text = film["regista"].ToString().Trim();
        txtTitolo.Text = film["titolo"].ToString().Trim();
        txtTrailer.Text = film["trailer"].ToString().Trim();
        txtTrama.Text = film["trama"].ToString().Trim();
        inserisciFilmCombo(ref cmbGenere,ref cmbNaz);
        cmbGenere.SelectedValue = film["genere"];
        cmbNaz.SelectedValue = film["nazionalita"];
        if ((bool)film["pellicola"])
        {
            chkPellicola.Checked = true;
        }
        if ((bool)film["digitale"])
        {
            chkDigitale.Checked = true;
        }
        if ((bool)film["tridimensionale"])
        {
            chk3d.Checked = true;
        }
        return short.Parse(film["id"].ToString());
    }

Through another button the user can update (in the dataset) the informations. This is the method:

        public void aggiornaFilm(short id, string titolo, string regista, string cast, int anno, int durata, string trama, string trailer, string genere, string nazionalita, string locandina, bool pellicola, bool digitale, bool tridimensionale)
    {
        dsCinema.filmRow film = cinema.film.FindByid(id);
        if (!titolo.Equals(""))
        { film["titolo"] = titolo; }
        if (!regista.Equals(""))
        { film["regista"] = regista; }
        if (!cast.Equals(""))
        { film["cast"] = cast; }
        if (!trama.Equals(""))
        { film["trama"] = trama; }
        if (!trailer.Equals(""))
        { film["trailer"] = trailer; }
        if (!genere.Equals(""))
        { film["genere"] = genere; }
        if (!locandina.Equals(""))
        { film["locandina"] = locandina; }
        if (!anno.ToString().Equals(""))
        { film["anno"] = anno; }
        if (!nazionalita.Equals(""))
        { film["nazionalita"] = nazionalita; }
        if (!durata.ToString().Equals(""))
        { film["durata"] = durata; }
        film["pellicola"] = pellicola;
        film["digitale"] = digitale;
        film["tridimensionale"] = tridimensionale;
    }

When I try to use these functions Visul Studio spit the folowing exception:

System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="BusinessLogicalLayer"

I've noticed that the dataset (at the beginning of "aggiornaFilm") is empty (so obviously yhe find method returns null) despite I've injected data through "popolaModificaFilm". Both the method (aggiornaFilm & popolaModificaFilm) are in the same class and are called in the same form.

Tnx for any help, sorry for my poor english.

A: 

It seems like your service object does not return data correctly. You should check that the services runs correctly.

Dominik Fretz
Sorry, didn't underlined that: when I first call the object "service" the dataset "cinema" contains rows.But when I query the dataset to extract the film with the given id I've receive a null response (through the debugger I've discovered the the dataset is indeed null).
Abaco
I would check the code for any 'cinema = null' assignment. Or probably you calling some initializing function somewhere. An object would not just out of the blue become null
Dominik Fretz
A: 

is it empty or is it null ? is cinema is null ?

You are accessing something (using the dot operator) but the left side of the dot is null - hence throwing this exception.

Step through the code to find the exact row the throws the exception and see what is wrong.

(even if not in this class but in the service you're calling) - the debugger is your friend here

Dani