SubSonic Forums
All Your Database Are Belong To Us

Updating a record - question

Latest post 10-19-2008 11:01 PM by martin1b. 2 replies.
  • 10-17-2008 12:30 AM

    Updating a record - question

    I'm using 2.1 and am updating a record. When I run the update I get the error 'Incorrect syntax near the keyword WHERE'. I've seen this is a bug and I've applied the patch to the SQL2005 generator, regenerated the code and got the same error. I even tried what was referenced here : http://forums.subsonicproject.com/forums/p/3488/14473.aspx#14473. Same issue.

     

    Thoughts on what I'm doing wrong? Code is posted below. Is there an alternate or better way to update a record?

     

    Second question. When doing an update, can I only specify the columns that changed or do I have to specify every column?

     


    Here's the code:

     

    TblContract t = new TblContract();
    t.IsNew = false;

     t.ContractID = Convert.ToInt32(dsCurrentRecord.Tables[0].Rows[0]["ContractID"].ToString()); //primary key
     t.DepartureCity = txtDepartureCity.Text;

    t.Save();

     

    I must say that I discovered subsonic earlier this week with the help of a friend and have to say it is AWESOME!!!! Why can't all data connectivity be this easy!!!

  • 10-19-2008 11:59 AM In reply to

    Re: Updating a record - question

    Reply |Contact |Answer

    Try this

    TblContract t = new TblContract();
    t.MarkOld();
    t.IsLoaded = true;

    t.ContractID = Convert.ToInt32(dsCurrentRecord.Tables[0].Rows[0]["ContractID"].ToString()); //primary key
    //This might be better //t.ContractID = (int)dsCurrentRecord.Tables[0].Rows[0]["ContractID"]; //primary key
    t.DepartureCity = txtDepartureCity.Text;

    t.Save();

     

    I think you just need to set the column that changed

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 10-19-2008 11:01 PM In reply to

    Re: Updating a record - question

    Works great. THANK YOU!!! Subsonic is just awesome!

Page 1 of 1 (3 items) | RSS