Showing posts with label foreign. Show all posts
Showing posts with label foreign. Show all posts

Monday, March 26, 2012

new table to ASPNetDb.mdf and foreign key

I was thinking of adding tables to ASPNetDB.mdf and have one of those tables have column userid as a foreign key from aspnet_Users

When I try to create relationship in Diagram, I get error saying that "data typ properties does not match"

userid in aspNet_Users is uniqueidentifier and userid (fk) in new table is int

What should I use, should I do that at all?

Thanks

uniqueidentifier and int is of different type. correct me if i'm wrong, the foreign key must be of same type as the primary key.|||

yes, but even when I use same type it gives me the same error

|||

Try to compare your new table with aspnet_Membership table, this table has an existing relationship with aspnet_Users table. Maybe you are missing a declaration of keys. As you can see both tables has UserID and they are tagged as a primary key and created a relationship based on that keys, but you can always have an option to make it an additional key instead of a primary.

Hope this helps.

|||That helps, good advice. I was able to connect keys from membership table with no problems. Thank you.

Monday, March 19, 2012

New record results in blank foreign key in subform

Hello,

I have a form with a subform. The mainform has a primary key ([ID]) and the subform has a foreign key ([MasterID]). When new records are added in the mainform, I get an error message that says, "ODBC -- Call Failed." The error message goes on to say that it cannot insert a null value into the column [MasterID], the foreign key in my subform.

[ID] and [MasterID] are in a one-to-one relationship. The data in the main form represents information at an initial state and the data in the subform represents an end state.

The error message seems to happen before the form's Before Insert event, so I am really at a loss as to how to fix this. I am new to SQL server. The backend files are on SQL server and the front end is running on Access in an MDB file.

Thanks,
JoshSorry, I figured out what was going on - my relationship was not set up correctly. I had test data in my child table with no parent. This caused the relationship to save incorrectly.