473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Store procedure doesn't work for web application.

I have one store procedure, which works fine in SQL Analyzer when I test it out, but doesn't work when I call it in web application. the problem is it doesn't insert last line, and the problem is that one Select statement doesn't execute, does anyone have a clue for this?

IF @CourseList <> '' AND @EmployeeID <> 'DELETE'
BEGIN
SELECT @npos1Course = 1
SELECT @npos1RBY = 1
SELECT @nLoop = 1
SELECT @nBreak = 0

WHILE (1 = 1)
BEGIN
SELECT @npos2Course = ISNULL(charindex(',', @CourseList, @npos1Course), 0)
SELECT @npos2RBY = ISNULL(charindex(',', @ReqdDate, @npos1RBY), 0)

IF @npos2Course = 0
BEGIN
SELECT @npos2Course = LEN(@CourseList)
SELECT @nBreak = 1
END
IF @npos2RBY = 0
BEGIN
SELECT @npos2RBY = LEN(@ReqdDate)
SELECT @nBreak = 1
END

SELECT @nLengthCourse = @npos2Course - @npos1Course
SELECT @nLengthRBY = @npos2RBY - @npos1RBY

IF @nBreak = 1
BEGIN
SELECT @nLengthCourse = @nLengthCourse + 1
SELECT @nLengthRBY = @nLengthRBY + 1
END

IF @nLengthCourse > 0
BEGIN
SELECT @nValueCourse = SUBSTRING(@CourseList, @npos1Course, @nLengthCourse)
IF @nlengthRBY > 0
SELECT @nValueRBY = SUBSTRING(@ReqdDate, @npos1RBY, @nLengthRBY)


SELECT @CourseID = a.CourseID
FROM Courses a INNER JOIN OrgCourses b ON a.CourseID = b.CourseID
WHERE a.CourseCode = @nValueCourse AND b.OrgID = @OrgID

insert into debug values (@CourseID, @UserID, @OrgID, @nValueRBY,@npos1Course, @npos2Course)

-- BEGIN to add or delete user courses and grade book
IF RTRIM(LTRIM(@nValueRBY)) = 'DELETE' -- delete user course registration
BEGIN
SELECT @CourseID = a.CourseID
FROM Courses a INNER JOIN OrgCourses b ON a.CourseID = b.CourseID
WHERE a.CourseCode = @nValueCourse AND b.OrgID = @OrgID

DELETE
FROM UserCourses
WHERE UserID = @UserID
AND CourseID = @CourseID

DELETE
FROM GradeBook
WHERE UserID = @UserID
AND CourseID = @CourseID
END
ELSE
BEGIN

IF NOT EXISTS ( SELECT UserID FROM UserCourses WHERE CourseID = @CourseID AND UserID = @UserID)
BEGIN
IF Exists (Select CourseID from Courses Where CourseID = @CourseID)
BEGIN

IF @nLengthRBY > 0
BEGIN
INSERT INTO UserCourses(UserID, OrgID, CourseID, ExamSubmissions, ContentBookmark, ExamBookmark,
RequiredByDate, EmailDistribution, Instructor, LastLessonComplete, CreateDate,status)
VALUES
(@UserID, @OrgID, @CourseID, 0, 0, 0, CAST(RTRIM(LTRIM(@nValueRBY)) AS SMALLDATETIME), 0, 0, 0, getdate(),0)
END
ELSE
BEGIN
INSERT INTO UserCourses(UserID, OrgID, CourseID, ExamSubmissions, ContentBookmark, ExamBookmark,
RequiredByDate, EmailDistribution, Instructor, LastLessonComplete, CreateDate,status)
VALUES
(@UserID, @OrgID, @CourseID, 0, 0, 0, NULL, 0, 0, 0, getdate(),0)
END
IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
SELECT -2 Status -- failed to add User Course entry
RETURN
END

INSERT INTO GradeBook
(CourseID, UserID, OrgID, Grade, Status)
VALUES
(@CourseID, @UserID, @OrgID, 0, 1)

IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
SELECT -1 Status -- error adding log-on account
RETURN
END
END
END
END
END

IF @nBreak = 1
BREAK

SELECT @npos1Course = @npos2Course + 1
SELECT @npos1RBY = @npos2RBY + 1
SELECT @nLoop = @nLoop + 1
SELECT @CourseID = 0
END
END
Oct 19 '06 #1
0 1240

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: kids_pro | last post by:
Hi there, I create a store procedure call GetPayment(@dtFrom DATETIME, @dtEnd DATETIME) After that I design a report using that store procedure I select crystal report in this case. I can...
3
by: serge calderara | last post by:
Dear all, One simple question relative to store procedure withinh ASP code on a web page. Let say that I am calling a store procedure to execute from a server button click on my web page. That...
3
by: Hrvoje Voda | last post by:
I have this code: SqlConnection conn = null; string Table=""; int rCount; conn = new
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
0
by: rxding | last post by:
Hello, Performance reason we need to move some of our code into database. Java Store Procedure is given the first choice. However, while investigating some sample code of Java store procedure, ...
11
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store...
1
by: TC | last post by:
I'm confused about the proper way to shut down my application. I have a form which instantiates a control, which instantiates another control, which instantiates yet another control that runs a...
0
by: sreemati | last post by:
Hi Everyone, I had an ASP page which takes all the column values in array and then passes it to store procedure. Now one of the variable in the store procedure needs to be changed from int to real...
0
by: seep | last post by:
salam to everyone.. as a new bee in .net i m finding lot of difficulty. i want to get all records of a table from database via store procedure.but spending many days i dont know how can i do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.