Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Stuck trying to learn to do SubmitChanges

Stuck trying to learn to do SubmitChanges

Scheduled Pinned Locked Moved C#
helpdatabasequestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nigel Mackay
    wrote on last edited by
    #1

    The table (Password) has only 1 column (Password1) and only 1 row. It is also the PrimaryKey. I can retrieve the password:

    thePassword =
    from tt in MainMenu.db.Password
    select tt;
    try
    {
    password = thePassword.ElementAt(0).Password1;
    ...

    I am trying to change the value.

    if ((from tt in MainMenu.db.Password
    select tt).Count() > 0)
    {
    Password zz = MainMenu.db.Password.Single(); // or ElementAt(0) or ??
    zz.Password1 = newPassword;
    try
    {
    MainMenu.db.SubmitChanges();
    }
    ...

    I get the runtime error "A member defining the identity of the object cannot be changed ..."

    S N 2 Replies Last reply
    0
    • N Nigel Mackay

      The table (Password) has only 1 column (Password1) and only 1 row. It is also the PrimaryKey. I can retrieve the password:

      thePassword =
      from tt in MainMenu.db.Password
      select tt;
      try
      {
      password = thePassword.ElementAt(0).Password1;
      ...

      I am trying to change the value.

      if ((from tt in MainMenu.db.Password
      select tt).Count() > 0)
      {
      Password zz = MainMenu.db.Password.Single(); // or ElementAt(0) or ??
      zz.Password1 = newPassword;
      try
      {
      MainMenu.db.SubmitChanges();
      }
      ...

      I get the runtime error "A member defining the identity of the object cannot be changed ..."

      S Offline
      S Offline
      Som Shekhar
      wrote on last edited by
      #2

      as a practice, password column shouldn't be the primary key because you may want to change it later. Also, more than one users can have the same password. Usually username could be used as a key or simply adding a new id.

      Nigel Mackay wrote:

      I get the runtime error "A member defining the identity of the object cannot be changed ..."

      Looks like that you are trying to change the password => primary key..

      N 1 Reply Last reply
      0
      • S Som Shekhar

        as a practice, password column shouldn't be the primary key because you may want to change it later. Also, more than one users can have the same password. Usually username could be used as a key or simply adding a new id.

        Nigel Mackay wrote:

        I get the runtime error "A member defining the identity of the object cannot be changed ..."

        Looks like that you are trying to change the password => primary key..

        N Offline
        N Offline
        Nigel Mackay
        wrote on last edited by
        #3

        Removed the primary key assignment. Still gives same problem. There is only one password in this app, and it is not there to discriminate between users, it is there because certain dangerous operations require a password so that only competent workers can do them!! Just think of it as a table that stores only 1 string.

        1 Reply Last reply
        0
        • N Nigel Mackay

          The table (Password) has only 1 column (Password1) and only 1 row. It is also the PrimaryKey. I can retrieve the password:

          thePassword =
          from tt in MainMenu.db.Password
          select tt;
          try
          {
          password = thePassword.ElementAt(0).Password1;
          ...

          I am trying to change the value.

          if ((from tt in MainMenu.db.Password
          select tt).Count() > 0)
          {
          Password zz = MainMenu.db.Password.Single(); // or ElementAt(0) or ??
          zz.Password1 = newPassword;
          try
          {
          MainMenu.db.SubmitChanges();
          }
          ...

          I get the runtime error "A member defining the identity of the object cannot be changed ..."

          N Offline
          N Offline
          Nigel Mackay
          wrote on last edited by
          #4

          Found problem. Must have a Primary Key, so added another column to be the primary Key and it works.

          S 1 Reply Last reply
          0
          • N Nigel Mackay

            Found problem. Must have a Primary Key, so added another column to be the primary Key and it works.

            S Offline
            S Offline
            Som Shekhar
            wrote on last edited by
            #5

            Som Shekhar wrote:

            Usually username could be used as a key or simply adding a new id.

            I suggested you that... You said you tried it?

            Nigel Mackay wrote:

            Found problem. Must have a Primary Key, so added another column to be the primary Key and it works.

            N 1 Reply Last reply
            0
            • S Som Shekhar

              Som Shekhar wrote:

              Usually username could be used as a key or simply adding a new id.

              I suggested you that... You said you tried it?

              Nigel Mackay wrote:

              Found problem. Must have a Primary Key, so added another column to be the primary Key and it works.

              N Offline
              N Offline
              Nigel Mackay
              wrote on last edited by
              #6

              I actually misinterpretted your answer, seeing only the bit about not using password as the primary key, and not adding another column for userID, because I don't need it, as I ony have one password. I later remembered that inserts, deletes and changes only work if there is a primary key. So I have a column for primary key with only 1 row in the table. And it will always only be 1 row!!

              S 1 Reply Last reply
              0
              • N Nigel Mackay

                I actually misinterpretted your answer, seeing only the bit about not using password as the primary key, and not adding another column for userID, because I don't need it, as I ony have one password. I later remembered that inserts, deletes and changes only work if there is a primary key. So I have a column for primary key with only 1 row in the table. And it will always only be 1 row!!

                S Offline
                S Offline
                Som Shekhar
                wrote on last edited by
                #7

                You always need an ID as a primary key. Even if you don't need it, always make it a point to add a key. There has to be one column in any table with unique values. Just as a practice. its a good habit.

                N 1 Reply Last reply
                0
                • S Som Shekhar

                  You always need an ID as a primary key. Even if you don't need it, always make it a point to add a key. There has to be one column in any table with unique values. Just as a practice. its a good habit.

                  N Offline
                  N Offline
                  Nigel Mackay
                  wrote on last edited by
                  #8

                  Every now and again one forgets :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups