R
Ryan
OK, here's my setup. I have a treeview control that is populated with
records from a Product table, and it allows "checking". This is used for my
automatic notification system. Say a particular Product is sold, any users
who have that boxed checked will get a notification. So my (shortened)
database layout is as such:
Product Table
ProductID (PK)
ProductName
User Table (the users of the program)
UserID (PK)
UserName
User_mm_Product Table (keeps track of what users want to me notified of
sales for which products)
UserProductID (PK)
UserID (FK)
ProductID (FK)
So what I have been trying to do is populate a datatable that contains
ProductID, ProductName (this is the only field that shows in the TreeView),
UserID, and UserProductID. It shows one record for each record in the
Product Table (Left outter join). Then I can cycle through each of these
records one at a time - if the item is checked and UserID already exists, do
nothing - if the item is unchecked and UserID is Null, do nothing. If the
item is checked and UserID is Null, I need to INSERT a record into
User_mm_Product. If the item is unchecked and UserID is not null, I need to
delete the record for the current UserProductID.
Anyways, I keep getting a constraint error, probably because its trying to
populate UserID and UserProductID's with Null values when I .Fill the
datatable. Just looking for suggestions if their's an easier way to do this
or if I'm on the right track. Below is the stored procedure I created to
populate the datatable.
Thanks,
Ryan
SELECT P.ProductName, P.ProductID, U.UserID, U.UserProductID
FROM Product AS P LEFT OUTER JOIN
(SELECT ProductID, UserID, UserProductID
FROM User_mm_Product
WHERE (UserID = @UserID)) AS U ON P.ProductID = U.ProductID
records from a Product table, and it allows "checking". This is used for my
automatic notification system. Say a particular Product is sold, any users
who have that boxed checked will get a notification. So my (shortened)
database layout is as such:
Product Table
ProductID (PK)
ProductName
User Table (the users of the program)
UserID (PK)
UserName
User_mm_Product Table (keeps track of what users want to me notified of
sales for which products)
UserProductID (PK)
UserID (FK)
ProductID (FK)
So what I have been trying to do is populate a datatable that contains
ProductID, ProductName (this is the only field that shows in the TreeView),
UserID, and UserProductID. It shows one record for each record in the
Product Table (Left outter join). Then I can cycle through each of these
records one at a time - if the item is checked and UserID already exists, do
nothing - if the item is unchecked and UserID is Null, do nothing. If the
item is checked and UserID is Null, I need to INSERT a record into
User_mm_Product. If the item is unchecked and UserID is not null, I need to
delete the record for the current UserProductID.
Anyways, I keep getting a constraint error, probably because its trying to
populate UserID and UserProductID's with Null values when I .Fill the
datatable. Just looking for suggestions if their's an easier way to do this
or if I'm on the right track. Below is the stored procedure I created to
populate the datatable.
Thanks,
Ryan
SELECT P.ProductName, P.ProductID, U.UserID, U.UserProductID
FROM Product AS P LEFT OUTER JOIN
(SELECT ProductID, UserID, UserProductID
FROM User_mm_Product
WHERE (UserID = @UserID)) AS U ON P.ProductID = U.ProductID