开发者

Rows added to databank disappear after re-run of the program

开发者 https://www.devze.com 2023-04-01 15:38 出处:网络
I\'m making a rather \"simple\" piece of software and at the moment I\'m working with one table in my database and reading from the database works and now I was trying to implement inserting into the

I'm making a rather "simple" piece of software and at the moment I'm working with one table in my database and reading from the database works and now I was trying to implement inserting into the database, which seems to work as long as the program is running, but when I stop the program (stop debugging in VS) and launch it again, the rows don't seem to be in the database (already checked the .mdf database itself for the rows but they can't be found).

This is the piece of code:

public void saveKlant(klant n开发者_运维知识库ieuweKlant)
{
    KlantGegevens newKlant = new KlantGegevens();
    newKlant.klantNaam = nieuweKlant.naam;
    newKlant.klantStraat = nieuweKlant.straat;
    newKlant.klantPostcode = nieuweKlant.postcode;
    newKlant.klantHuisNummer = nieuweKlant.huisnummer;
    newKlant.klantGSM = nieuweKlant.gsm;
    newKlant.klantTel = nieuweKlant.telnummer;
    newKlant.klantGebDatum = nieuweKlant.gebDatum;
    newKlant.klantEmail = nieuweKlant.email;

    using (kapsalonEntities context = new kapsalonEntities())
    {
        try
        {
            context.KlantGegevens.AddObject(newKlant);
            int test = context.SaveChanges();
        }
        catch
        {
            throw new InvalidOperationException("het object kon niet toegevoegd worden");
        }
    }
}

"test" equals 1 (so context.SaveCHanges() = 1) when running the program.

what would be the reason for the data to not be added persistently? since I do use a Context.SaveChanges()?

Thanks in advance.


It looks like you didn't check of the property where the database each time copies himself toi the debug directory. That's why you always get your default data again. Set the property to "if newer"

0

精彩评论

暂无评论...
验证码 换一张
取 消