Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Trigger Question

Author  Topic 

WelshPunk
Yak Posting Veteran

67 Posts

Posted - 2007-07-03 : 05:50:23
Hello All

I am using asp.net 2.0 and SQL Server 2000. I am using a datagrid footer template to insert a new row into a datagrid. The process involves

Create a new project into a project table. Then on the projects datagrid by selecting a project it should then populate an hours datagrid in a master detail scenario. I managed to overcome the first problem - how could the hours datagrid be populated when there is no valid hours for the newly created project. I created a trigger on the project (tgCreateHourRow)table that inserted a row into the hours table with just the project_id taken from the row just inserted into the project table. This fixed the problem and then allowed the hours grid to be populated and therefor it is shown - and the footer is exposed and enables me to enter and insert new FULL row into the hours table which is then displayed in the grid. This works fine but leaves me with a temporary row (which only displays the project_id) which I need to remove after the insert of the full row.

My problem.... I want to put a trigger on the hours table that would remove the temporary row AFTER the completed full insert into the hours table.

Are there any clever sql junkies out there that can help please?

Phill

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-03 : 05:54:54
well if you know the id of the row you can delete it in the trigger, no?

although i don't quite understand your design. stuff like that usually doesn't present a problem.
datasets handle master-child data pretty well.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

WelshPunk
Yak Posting Veteran

67 Posts

Posted - 2007-07-03 : 06:16:21
Ideally what I need is some way of writing a trigger on the insert of a new record on the hours table that could somehow check to see if a full row has just been inserted and then remove the temporary row. I also have more than one using the same application so I have to take that into consideration. i am new to this so I apologize for my lack of knowledge.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-03 : 06:18:43
well in the trigger you can query inserted psudo table that holds inserted rows.
select * from inserted




_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

WelshPunk
Yak Posting Veteran

67 Posts

Posted - 2007-07-03 : 06:38:07
Sorry for being dim here
Here is my original trigger that puts a temporary row into the hours table

CREATE TRIGGER [tgAddHour] ON [dbo].[tele_work_project]
FOR INSERT
AS
INSERT INTO tele_work_hours(twh_project_id)
SELECT MAX(tele_work_project.tw_project_id) as MaxProjectID
FROM tele_work_project

If I create a simillar one on the hours table it will remove the temporary row (which is needed initially to allow new rows to be entered in the hours datagrid)

CREATE TRIGGER [tgRemoveTempRow] on [dbo].[tele_work_hours]
FOR INSERT
AS
DELETE * FROM dbo.tele_work_hours
WHERE emp_no ISNULL

Which is one of the temp row fields which should be empty
Go to Top of Page
   

- Advertisement -