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

Wednesday, March 7, 2012

My Table that uses aspnet foreign Keys wont display anything - CAUTION - Noob at work

I've created a new table in ASPNETDB.mdf called 'customerInfo'. Most of the fields are, for the moment, data that exists in one of the existing ASPNET tables eg Membership_UserId (primary key), Membership_Email, Users_UserName etc.; the list goes on. I have put a new column 'amountspent' - just to test that I can do what I think I can do, however the table doesn't display any data. Am I OK in thinking that I can use the aspnet data in my own tables and reference through foreign keys to them. I've made sure that the procedure that I used to put the table into a gridview on the webpage is OK as I did the same thing to the membership table and that displays all of its data. Can someone either explain the steps I need to make this happen correctly or point me in the direction of a noob type walkthrough.

Thanks

ps I've used several different ways to link the tables. First I tried building the relationships through the SqlMembershipProvider, created tables and added the foreign keys. Not sure of whether I'd done this correctly, I then used the diagram method which is pretty straightforward, however the result is the same. Surely now these tables are keyed to the UserId of aspnet_Users they should build and display a table of my existing test membership - even if the other fields, for the moment, are not carrying any data?

Monday, February 20, 2012

My own little piece of SQL Wierdness

This has me stumped.
I have a parent and a child table with a constraint on the parent's foreign
key in
the child.
So with this in mind, every once in a while when I am exporting data, I get
an error
that there is a row in the child table with and ID that is not in the parent
table.
One of our programmers is using ADO transactions and beginning it in source
code (not
a proc). Then he adds a row to the parent table, gets the ID in one proc an
d adds a
row to the child table in another proc. Then he commits or aborts when he g
ets back
to code.
Can you think of any reason why the row in the child table is there, but the
row in
the parent isn't there when exporting data?
Thanks.Do you have foreign key constraints on your tables? If so, then it sounds
like a query issue. Otherwise, my guess is the programs arent doing
"something" right?
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"Mike Malter" <mikemalter@.newsgroup.nospam> wrote in message
news:ut9Jr40pFHA.3524@.tk2msftngp13.phx.gbl...
> This has me stumped.
> I have a parent and a child table with a constraint on the parent's
> foreign key in the child.
> So with this in mind, every once in a while when I am exporting data, I
> get an error that there is a row in the child table with and ID that is
> not in the parent table.
> One of our programmers is using ADO transactions and beginning it in
> source code (not a proc). Then he adds a row to the parent table, gets
> the ID in one proc and adds a row to the child table in another proc.
> Then he commits or aborts when he gets back to code.
> Can you think of any reason why the row in the child table is there, but
> the row in the parent isn't there when exporting data?
> Thanks.
>|||The foreign key constraint is not being enforced.
exec sp_helpconstraint N'tableName'
The second result set contains a list of constraints. Check the
status_enabled column for the foreign key constraint in question. If it's
Disabled, then the constraint will not be enforced.
"Mike Malter" <mikemalter@.newsgroup.nospam> wrote in message
news:ut9Jr40pFHA.3524@.tk2msftngp13.phx.gbl...
> This has me stumped.
> I have a parent and a child table with a constraint on the parent's
foreign key in
> the child.
> So with this in mind, every once in a while when I am exporting data, I
get an error
> that there is a row in the child table with and ID that is not in the
parent table.
> One of our programmers is using ADO transactions and beginning it in
source code (not
> a proc). Then he adds a row to the parent table, gets the ID in one proc
and adds a
> row to the child table in another proc. Then he commits or aborts when he
gets back
> to code.
> Can you think of any reason why the row in the child table is there, but
the row in
> the parent isn't there when exporting data?
> Thanks.
>