1

With this code there is no change in my database. when the above code is run there is no longer a new entry created neither is an entry updated.

public void UpdateCallback(callback cb_)
    {
        callback call = context.callbacks.Single(c => c.callbackID == cb_.callbackID);

            //call.callbackID = cb_.callbackID;
            call.status = cb_.status;
            call.contactName = cb_.contactName;
            call.company = cb_.company;
            call.phone = cb_.phone;
            call.calledDate = cb_.calledDate;
            call.callback1 = cb_.callback1;
            call.notes = cb_.notes;

        try
        {
            context.SubmitChanges();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }

2 Answers 2

4

This post is similar to yours.

In his case, the update did not work because the table did not have a primary key.

Have you verified that CallbackId is defined as a PK in the database?

3
  • I've had this issue, with that cause as well.
    – Blorgbeard
    Apr 24, 2009 at 7:26
  • For clarity, it is not the existence of a primary key in the database that matter here but whether one or more columns that uniquely identify records are marked as primary keys in the Linq-to-SQL designer. In other words, even if there is no PK in the db, marking column(s) that can logically act as PK as primary key is sufficient.
    – KristoferA
    Apr 24, 2009 at 7:32
  • .. you can do that in the designer? arg!
    – Blorgbeard
    Apr 29, 2009 at 23:16
0

Nothing immediate jumps out at me. I have found it useful to use the Log property of the DataContext to see the SQL being generated.

See http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.log.aspx

You could then use something like the code below to output the SQL to the Visual Studio Debug window while debugging.

/// <summary>
/// Implementation of a <see cref="TextWriter"/> that outputs to the debug window
/// </summary>
public class DebugTextWriter : TextWriter
{
    public override void Write(char[] buffer, int index, int count)
    {
        System.Diagnostics.Debug.Write(new string(buffer, index, count));
    }

    public override void Write(string value)
    {
        System.Diagnostics.Debug.Write(value);
    }

    public override Encoding Encoding
    {
        get { return System.Text.Encoding.Default; }
    }
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.