I have the following code:
pillboxDataContext db = new pillboxDataContext();
userAccount newUser = new userAccount();
newUser.userName = "test123";
newUser.userPhone = "1234567890";
newUser.userEmail = "test@test.com";
newUser.userPwd = "testpassword";
newUser.userCreateDate = DateTime.Now;
newUser.userAccountType = "basic";
db.users.Add(newUser);
db.SubmitChanges();
userAccount is my object with properties (that match up with the user table).
I’m confused on the db.users.Add(newUser); line. The .Add is stating: System.Data.LINQ.Table does not contain a definition for ‘Add’.
The examples I was following seem to indicate that the .Add should be allowed. I’m new at this so please any advice would be very helpful.
UPDATE:
I changed it to db.users.InsertOnSubmit(newUser); however, I’m still getting an error:
The best overloaded method match for
‘System.Data.Linq.Table.InsertOnSubmit(user)’ has some invalid
arguments
Fix!
After looking at other code samples I figured out that I was assigning my data to the class (userAccount) rather than the table (user).
So I changed: userAccount newUser = new userAccount(); to user newUser = new user();
Then everything worked like I expected.
Thanks for the info!
Yes,
Addwon’t work – I suspect you wantInsertOnSubmit.