0

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 debug, 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?

1 Answer 1

1

Never mind, no PK on table. I knew it was a n00b problem :P

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.