Object reference not set to an instance of an object. Table not found in the report not exist in th

Magezi SagesseMagezi Sagesse DRCONGO
edited 2:10PM in FastReport .NET
I have a form in Vb.net on which I put three different report object(chronoT,chronoAu,controleMois) and on previewcontrol in which I load those reports. For switching between those report I have a combobox that has 3 option; depending on what the user will choose in the combobox I load the corresponding report object in the previewcontrol.

The first report has two tables (chronogrammeTaches,synthesetaches),the second report has two tables also(chronoautre et syntheseautre) and the third has one table(controletachemois). I pass a custom sql command to fill those tables. to pass that custom sql command, I creat tabledatasource type variables that i refer to those report data tables and I load them in the preview control in three different procedure,here is how I do:

For the first report object in the procedure called chargerchronoObje:
dim tfiche as new tabledatasource,synthese as new tabledatasource
  tfiche = CType(chronoT.GetDataSource("ChronogrammeTache"), TableDataSource)
        synthese = CType(chronoT.GetDataSource("synthesertaches"), TableDataSource)
'Passing the custom sql command

 tfiche.SelectCommand = "SELECT DISTINCT taches.codet,taches.type,taches.tache,lignes.mois,lignes.coutu,lignes.annee FROM Taches INNER JOIN (RelierT INNER JOIN lignes  ON RelierT.codet = lignes.codet) ON taches.codet=RelierT.codet WHERE codep=a AND lignes.annee=b;"
  synthese.SelectCommand = "SELECT synthese.type, synthese.mois, synthese.annee, synthese.designationT, Count(synthese.codet) AS nbre, synthese.codea " & _
    "FROM (SELECT DISTINCT Taches.type, lignes.mois, Taches.codet, Taches.designationT, Taches.codea, lignes.annee " & _
    "FROM Taches INNER JOIN (RelierT INNER JOIN lignes ON RelierT.codet = lignes.codet) ON Taches.codet = RelierT.codet " & _
    "WHERE ((((Taches.codep)=a) AND (lignes.annee)=b)))  AS synthese GROUP BY synthese.type, synthese.mois, synthese.annee, synthese.designationT, synthese.codea;"

For the second in the procedure called chargerchronotache:
      dim tfiche1 as new tabledatasource, synthese1 as new tabledatasource
        tfiche1 = CType(chronoAu.GetDataSource("chronoautre"), TableDataSource)
        synthese1 = CType(chronoAu.GetDataSource("syntheseautre"), TableDataSource)
'Passing the custom sql command
 tfiche1.SelectCommand = "SELECT DISTINCT Specifiques.codes as codet,specifiques.codeG as codea,specifiques.specifique as tache, lignes.mois, 1 AS coutu,    lignes.annee FROM Specifiques INNER JOIN (activites INNER JOIN (Taches  INNER JOIN lignes ON taches.codet=lignes.codet) ON activites.codea=Taches.codea) ON specifiques.codes=activites.codes WHERE specifiques.codep=a AND lignes.annee=b"
   synthese1.SelectCommand = "SELECT Count(synthese.codet) AS Nbre,synthese.codea,synthese.mois, synthese.annee FROM (SELECT DISTINCT Specifiques.codes as codet,specifiques.codeG as codea,specifiques.specifique as tache, lignes.mois, 1 AS coutu, lignes.annee" & _
" FROM Specifiques INNER JOIN (activites INNER JOIN (Taches  INNER JOIN lignes ON taches.codet=lignes.codet) ON activites.codea=Taches.codea) ON specifiques.codes=activites.codes " & _
" WHERE activites.codep=a AND  lignes.annee=b) as synthese GROUP BY  synthese.codea,  synthese.mois, synthese.annee;"


For the third in the procedure called chargerControletache:
dim table As New TableDataSource
        table = CType(controleMois.GetDataSource("controletachemois"), TableDataSource)

'Passing custom sql command
 table.SelectCommand = "SELECT resume.codet, resume.type, resume.mois, resume.prevu, resume.realise AS realiser,(resume.prevu-resume.realise) AS ecart, ((([resume].[prevu]-[resume].[realise])*100)/[resume].[prevu]) AS ecartp, resume.annee FROM (SELECT synth.codet,synthe.type, synth.cout AS prevu, synth.mois, synth.annee, synthe.realise" & _
" FROM (SELECT lignes.codet,(lignes.coutu*lignes.frequence) as cout,lignes.mois,lignes.annee FROM lignes)  AS synth INNER JOIN (SELECT RelierT.codets as codet,lignes.mois,taches.type,SUM( IIf(IsNull([realisations.montantr]),0,[realisations.montantr])) AS realise, lignes.annee FROM RelierT INNER JOIN (taches INNER JOIN (lignes LEFT JOIN realisations ON lignes.ligne=realisations.ligne) ON taches.codet=lignes.codet) ON RelierT.codet=taches.codet WHERE taches.codep=a AND lignes.annee=b GROUP BY RelierT.codets,lignes.mois,type,lignes.annee)  AS synthe ON synth.codet = synthe.codet AND synth.mois=synthe.mois AND synth.annee=synthe.annee " & _
"GROUP BY synth.codet, synth.cout, synth.mois, synth.annee, synthe.realise,synthe.type) As resume"

When I load for the first time those report inside the previewcontrol by calling their respective procedure one after another; they are loaded well, THE PROBLEM IS when I load for the second time on of these reports after another one by calling its procedure; for example for the third report : the expression
table = CType(controleMois.GetDataSource("controletachemois"), TableDataSource)
sets the table to nothing or null (C#) to mean that the table controletachemois does'nt exist in the report object controleMois; I get an exception that says the reference not set to an instance of an object Unless l I close and reopen again the form and load it for the first time.

I don't understand what is wrong, I've tried all I can but nothing is resolved. Can someone assist me please!!!!!!

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.