开发者

Linq to SQL update not updating data, no exceptions c#

开发者 https://www.devze.com 2023-02-03 07:09 出处:网络
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

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

0

精彩评论

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