please be patient ;)

Posts   
 
    
radasys
User
Posts: 6
Joined: 18-Nov-2004
# Posted on: 04-Dec-2004 18:28:17   

as iam new to oop and c# (i am used to vb/sql with recordsets, and sp's) maybe my question will be a little bit stupid but i cant really find the problem. maybe a basic misunderstanding. cry

following code in the form:


KassenBuch aktKassenBuch = new KassenBuch("012004"); this.monatsAnfangsSaldo.Text = aktKassenBuch.MonatsAnfangsSaldo.ToString(); this.monatsEndeSaldo.Text = aktKassenBuch.MonatsAnfangsSaldo.ToString(); this.jahrMonat.Text= aktKassenBuch.JahrMonat; this.bemerkung.Text = aktKassenBuch.Bemerkung;



the class in the businesslayer: using System; using DAL; using DAL.EntityClasses; using DAL.HelperClasses; using DAL.FactoryClasses; using DAL.DatabaseSpecific; using SD.LLBLGen.Pro.ORMSupportClasses;

namespace rapidKassa.BLL { /// <summary> /// Zusammenfassung für Class1. /// </summary> public class KassenBuch { private KassenbuchEntity m_KassenBuch;

    public KassenBuch(string jahrmonat)
    {

        //
        // TODO: Fügen Sie hier die Konstruktorlogik hinzu
        //
        DataAccessAdapter adapter = new DataAccessAdapter();
        KassenbuchEntity m_KassenBuch = new KassenbuchEntity(jahrmonat);
        bool loadedCorrectly = adapter.FetchEntity(m_KassenBuch);
    }

    public string JahrMonat
    {
        get
        {
            return m_KassenBuch.JahrMonat;
        }
        set
        {
            m_KassenBuch.JahrMonat = value;
        }
    }

i get following error on the line return m_KassenBuch.JahrMonat;

Eine nicht behandelte Ausnahme des Typs 'System.NullReferenceException' ist in rapidkassa.bll.dll aufgetreten.

Zusätzliche Informationen: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

connection seems ok and ther must be a row ?

thanks for help.

thomas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 04-Dec-2004 18:51:00   

Could you paste the stack trace too please?

Either way, check if you've added the app.config appSettings from the generated app.config file to the .config file of your application project.

Frans Bouma | Lead developer LLBLGen Pro
radasys
User
Posts: 6
Joined: 18-Nov-2004
# Posted on: 04-Dec-2004 19:44:48   

StackTrace " at rapidKassa.BLL.KassenBuch.get_MonatsAnfangsSaldo() in f:\\entwicklung\\testprojekte\\rapidkassa\\rapidkassa.bll\\kassenbuch.cs:line 49\r\n at rapidkassa.GUI.mainF..ctor() in f:\\entwicklung\\testprojekte\\rapidkassa\\rapidkassa.gui\\mainf.cs:line 89\r\n at rapidkassa.GUI.mainF.Main() in f:\\entwicklung\\testprojekte\\rapidkassa\\rapidkassa.gui\\mainf.cs:line 795" string

hope you did mean this ? flushed you see the hole code in my post there is not more. the connection string is in the right app.config.


<?xml version="1.0"?> <configuration> <appSettings> <add key="Main.ConnectionString" value="data source=mob01;initial catalog=radasys;User ID=rapidsys;Password=****;persist security info=False;packet size=4096"/> </appSettings> </configuration>


when i call the entitiy direct in the form without the class KassenBuch it works. so the problem is maybe in the class kassenbuch ?

[code] public mainF() { // // Erforderlich für die Windows Form-Designerunterstützung // InitializeComponent(); DataAccessAdapter adapter = new DataAccessAdapter(); KassenbuchEntity aktKassenBuch = new KassenbuchEntity("012004"); bool loadedCorrectly = adapter.FetchEntity(aktKassenBuch); this.monatsAnfangsSaldo.Text = aktKassenBuch.MonatsAnfangsSaldo.ToString(); this.monatsEndeSaldo.Text = aktKassenBuch.MonatsAnfangsSaldo.ToString(); this.jahrMonat.Text= aktKassenBuch.JahrMonat; this.bemerkung.Text = aktKassenBuch.Bem;


its not that important on saturday evening wink better go for a beer

thanks thomas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 04-Dec-2004 20:01:10   

hmm. Does m_KassenBuch have a value in teh get clause? I think it's not, it's probably null. Still it should have a value though... odd.

Frans Bouma | Lead developer LLBLGen Pro
radasys
User
Posts: 6
Joined: 18-Nov-2004
# Posted on: 04-Dec-2004 20:54:31   

when I set a breakpoint on

adapter.FetchEntity(m_KassenBuch);

in the class then I have the right values in

return m_KassenBuch.MonatsAnfangsSaldo;

when I goto the next step (back into the form)

this.monatsAnfangsSaldo.Text = aktKassenBuch.MonatsAnfangsSaldo.ToString();

next step:

it jumps back into the class to the getproperty and then mKassenbuch itself is undefined and the value of the property is the exeption.

i am sure its just a beginner error and im missing something completly confused

thanks thomas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 05-Dec-2004 12:08:00   

Found it. This is really an annoyance of C#, I've had this a couple of times myself after a refactoring of a class and I forgot to remove the duplicate declaration. C# doesn't warn you if you re-define a class member variable in a deep internal scope. In the constructor, you redefine m_KassenBuch, i.e. you declare a local variable m_KassenBuch, and work with that variable.

so your class should look like:


namespace rapidKassa.BLL
{
    /// <summary>
    /// Zusammenfassung für Class1.
    /// </summary>
    public class KassenBuch
    {
        private KassenbuchEntity m_KassenBuch;

        public KassenBuch(string jahrmonat)
        {
            
            //
            // TODO: Fügen Sie hier die Konstruktorlogik hinzu
            //
            DataAccessAdapter adapter = new DataAccessAdapter();

            // next line is changed 
            m_KassenBuch = new KassenbuchEntity(jahrmonat);
            bool loadedCorrectly = adapter.FetchEntity(m_KassenBuch);
        }
...

Frans Bouma | Lead developer LLBLGen Pro
radasys
User
Posts: 6
Joined: 18-Nov-2004
# Posted on: 05-Dec-2004 17:02:19   

thanks a lot. smile

thomas