Linq to SQL update not updating data, no exceptions c#
I am trying to update a record in the database using Linq-to-SQL
.
DataContext db = new DataContext();
table t = (from c in db.table
where c.id == id
select c).SingleOrDefault();
I check to see if a record is returned or not and do an INSERT
or UPDATE
based on the results.
if(t != null)
{
t.column0 = data0;
t.column1 = data1;
t.column2 = data2
}
else
{
table n = new table();
n.column0 = data0;
n.column1 = data1;
n.columns2 = data2;
db.table.InsertOnSubmit(n);
}
try
{
db.SubmitChanges();
}
catch(ChangeConflictException e)
{
return e.Message;
}
I've stepped through it in d开发者_StackOverflow中文版ebug, the exception is never thrown and the database never gets updated. I'm still new with Linq so I figure I'm missing something...any ideas?
Never mind, no PK
on table. I knew it was a n00b problem :P
精彩评论