Showing posts with label displays. Show all posts
Showing posts with label displays. Show all posts

Monday, March 26, 2012

How to trace the records that have been related to the child table

The problem of mine is, I have a datagrid, Which displays data from a Employee(parent) table.

Now I want to delete some records based on the user selected checkbox,
only those records which has no related records in the EmployeeProject(child) can be deleted.
I want to know which are all the record that cannot be deleted?

How can I achieve this?

You need to find out the related records on the child tables by following the primary/foreign key relationships. In the future you can use theON DELETE CASCADE command, or similar, when you create a table, so it will delete all child records automatically. If you don't know the table relationships, I suggest you find out as much as possible about the structure you're working with before allowing data deletion.

|||

SELECT Employee.*,CASE WHEN EXISTS(SELECT * FROM EmployeeProject ep WHERE ep.EmployeeID=e.EmployeeID) THEN 0 ELSE 1 END AS Deletable

FROM Employee e

Then in your datagrid, make a button column that has a commandname of "Delete". Convert that column to a template field. Now databind the button's visible in the template field to Deletable. This isn't a perfect solution because changes can take place in the database from the time you generate the page until you get back the request to delete, but it handles the vast majority of cases. Just make sure you handle the case where you are requested to delete a record that either no longer exists (Most code will just silently fail anyhow), or is no longer deletable (Try/catch the attempt to delete, and on failure, re-databind the grid and toss up an error to the user).

|||

Sorry, didn't notice that you wanted checkboxes. Use the same query, just databind the checkbox'ed enabled property to the Deletable field.

Friday, March 9, 2012

How to suppress a field if it is null

I have a report where it displays demographic information. The Address2 field
is sometimes NULL and I haven't found a way to suppress this field. The only
thing I can do is make it invisible/visible with an IIF statement. I know in
Crystal Reports you could check a box that said "SUPPRESS IF BLANK" and this
would move all the other fields up on the report accordingly. With SQL
Reporting services it doesn't adjust the fields underneath it so I have a
blank/empty space. Does anyone know of any other things I can try.
ThanksHi GORAMS,
Are you using a table control? If so, take a look at the actual detail
line for Address2, and make sure that your IIF statement to control
visibility is set on the entire tablerow as opposed to just the
Address2 textbox. Just setting the visibility property on the Address2
textbox would cause your problem if the table has more than column.
Does this help?
Matt A
Rpeorting Services Newsletter at www.reportarchitex.com|||RS is shrinking fields if you specify that it is invisible (for example if
you put in Hidden property "=Fields!Something.Value is Nothing"). But, as in
CR, that depends of other fields in line, so if one is supperesed and other
one is not, it will not move fields under supperesed one up...
You can play arround little with columns maybe, or lists if you want to do
something like that..
Stjepan
"GORAMS" <GORAMS@.discussions.microsoft.com> wrote in message
news:A28602C1-D97C-4A19-9ABD-6A06D6A4A9BA@.microsoft.com...
>I have a report where it displays demographic information. The Address2
>field
> is sometimes NULL and I haven't found a way to suppress this field. The
> only
> thing I can do is make it invisible/visible with an IIF statement. I know
> in
> Crystal Reports you could check a box that said "SUPPRESS IF BLANK" and
> this
> would move all the other fields up on the report accordingly. With SQL
> Reporting services it doesn't adjust the fields underneath it so I have a
> blank/empty space. Does anyone know of any other things I can try.
> Thanks