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);
        }
    }
hlovdal
  • 26,565
  • 10
  • 94
  • 165
Sreedhar
  • 29,307
  • 34
  • 118
  • 188

2 Answers2

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?

Community
  • 1
  • 1
Jose Basilio
  • 50,714
  • 13
  • 121
  • 117
  • I've had this issue, with that cause as well. – Blorgbeard Apr 24 '09 at 07: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 '09 at 07:32
  • .. you can do that in the designer? arg! – Blorgbeard Apr 29 '09 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; }
    }
}
BBQ Snags
  • 263
  • 2
  • 6