Tuesday, March 27, 2012

Cursor isn''t being created.

ElementTypeDep_Cursor seems is not being created in this stored procedure:

Code Snippet

ALTER procedure spCopyTemplateElementTypesToIssues

@.TemplateRecno integer,

@.ProjRecNo integer,

@.IssueRecNo integer

as

declare @.ElementTypeRecno integer

declare @.ElementTypeDepRecno integer

declare @.ProjTypeRecno integer

declare @.PreElementRecNo integer

declare @.PostElementRecno integer

declare @.Count integer

DECLARE element_Cursor CURSOR FOR

SELECT ElementTypeRecNo

FROM dbo.tblTemplateElementType

where TemplateRecno = @.TemplateRecNo

OPEN element_cursor

FETCH NEXT FROM Element_Cursor into @.ElementTypeRecno

--delete from tblElementCPO

WHILE @.@.FETCH_STATUS = 0

BEGIN

select @.count = count (*)

from tblElementCPO

where ProjRecno = @.ProjRecNo

and IssueRecno = @.IssueRecno

and TemplateRecno = @.TemplateRecno

and ElementTypeRecno = @.ElementTypeRecNo

if @.Count = 0

begin

insert into tblElementCPO(Ignore, ElementTypeRecno, IssueRecno,

ProjRecno, MaxAttemptNum, IsMileStone, ComponentOnly, Phase,

TaskHoursEst, TemplateRecNo, ChangeDate, ChangePerson)

values (0, @.ElementTypeRecno, @.IssueRecno,

@.ProjRecno, 5,0,6,99,

99,@.TemplateRecno, getdate(), current_user)

end

FETCH NEXT FROM element_Cursor into @.ElementTypeRecno

END

CLOSE element_Cursor

DEALLOCATE element_Cursor

select @.Count = count (*)

FROM dbo.tblElementTypeDep

where TemplateRecno = @.TemplateRecNo

if @.Count > 0 then

begin

DECLARE ElementTypeDep_Cursor CURSOR FOR

SELECT ElementTypeDepRecNo, PreElementTypeRecNo, PostElementTypeRecno

FROM dbo.tblElementTypeDep

where TemplateRecno = @.TemplateRecNo

OPEN ElementTypeDep_cursor

FETCH NEXT FROM ElementTypeDep_Cursor

into @.ElementTypeDepRecno, @.PreElementRecNo, @.PostElementRecno

WHILE @.@.FETCH_STATUS = 0

BEGIN

select @.Count = count (*)

from tblElementDepCPO

where ElementTypeDepRecno = @.ElementTypeDepRecno

and PreElementRecNo = @.PreElementRecNo

and PostElementRecno = @.PostElementRecno

if @.Count = 0

begin

insert tblElementDepCPO (ElementTypeDepRecno, PreElementRecNo,

PostElementRecno, ChangeDate, ChangePerson)

values (@.ElementTypeDepRecno, @.PreElementRecNo,

@.PostElementRecno, getdate(), current_user)

end

FETCH NEXT FROM ElementTypeDep_Cursor

into @.ElementTypeDepRecno, @.PreElementRecNo, @.PostElementRecno

END

CLOSE elementTypeDep_Cursor

DEALLOCATE elementTypeDep_Cursor

end

called by

Code Snippet

Dim cnQI02414 As New SqlConnection(My.Settings.csQI02414Dev)

Dim cmd As New SqlCommand

Dim reader As SqlDataReader

cmd.CommandText = "spCopyTemplateElementTypesToIssues"

cmd.CommandType = CommandType.StoredProcedure

Dim spmTemplateRecNo As SqlParameter = _

cmd.Parameters.Add("@.TemplateRecNo", SqlDbType.Int)

spmTemplateRecNo.Value = _

Me.cbTemplate.SelectedValue

Dim spmProjRecNo As SqlParameter = _

cmd.Parameters.Add("@.ProjRecNo", SqlDbType.Int)

spmProjRecNo.Value = _

Me.cbProject.SelectedValue

Dim spmIssueRecNo As SqlParameter = _

cmd.Parameters.Add("@.IssueRecNo", SqlDbType.Int)

spmIssueRecNo.Value = _

Me.cbIssue.SelectedValue

cmd.Connection = cnQI02414

cnQI02414.Open()

reader = cmd.ExecuteReader()

' Data is accessible through the DataReader object here.

cnQI02414.Close()

What should I be looking for?

You're not returning anything from the stored procedure. i.e. there is no "select" after you're done inserting. So, your reader will be empty.

To verify if your sproc actually runs, try returning all input and output parameters as the last "select" statement.

No comments:

Post a Comment