I want to input data into my table (sql 2008) using linq to sql:
public static bool saveEmail(Emailadressen email)
{
TBL_Emailadressen saveMail = new TBL_Emailadressen();
destil_loterijDataContext db = new destil_loterijDataContext();
saveMail.naam = email.naam;
saveMail.emailadres = email.emailadres;
saveMail.lotnummer = email.lotnummer;
try
{
saveMail.naam = email.naam;
saveMail.lotnummer = email.lotnummer;
saveMail.emailadres = email.emailadres;
db.TBL_Emailadressens.InsertOnSubmit(saveMail);
return true;
}
catch (Exception ex)
{
Console.WriteLine("Opslaan niet gelukt!" + ex.ToString());
return false;
}
}
For some reason nothing is being added to this table. My table has the following fields:
ID (Auto incr int)
Naam (varchar50)
lotnummer (varchar50)
emailadres (varchar50)
My object im trying to save (saveMail) always has an ID = 0 , and i don't know why. I think that is preventing me from saving to the DB?