views:

348

answers:

2

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);
        }
    }
A: 

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; }
    }
}
Brett Carswell
+2  A: 

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?

Jose Basilio
I've had this issue, with that cause as well.
Blorgbeard
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 - Huagati.com
.. you can do that in the designer? arg!
Blorgbeard