Stuck trying to learn to do SubmitChanges
-
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 ..."
-
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 ..."
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..
-
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..
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.
-
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 ..."
Found problem. Must have a Primary Key, so added another column to be the primary Key and it works.
-
Found problem. Must have a Primary Key, so added another column to be the primary Key and it works.
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.
-
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.
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!!
-
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!!
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.
-
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.
Every now and again one forgets :)