Hi guys, I have a store procedure that inserts into a table, this procedure is trying to insert differnt coursecode against one person in each row of my table so it is expected that when i call this procedure from my page only one parameter will changeing in all the rows inserted. form my class I pass these parameters that will not change as constants and the changing one as content of ListBox.I then use loop to excute the Procedure as many times as there are items in my listBox in the process changing the dynamic parameter to item in the lisBox at every loop. my problem is that if i have only one item in the listBox the code will insert successfull,but if i have more than one item in the ListBox an exception that "Procedure or function STP_STUDENTCOURSEREGISTERED_INSERT1 has too many arguments specified" will be throw. STP_STUDENTCOURSEREGISTERED_INSERT1 is the name of my stored procedure. help me fix this bug. the code from my class that executes the procedure is pasted below Public Sub AddRegisteredCourse(ByVal StudentId As Integer, ByVal SessionId As Int16, ByVal StudentLevel As String, ByVal Semester As String, ByVal LisCourseCode As ListBox, ByVal CourseMajorCode As String) objcommand.CommandText = "STP_STUDENTCOURSEREGISTERED_INSERT1" Dim i As Int16 For i = 0 To LisCourseCode.Items.Count - 1 With objcommand.Parameters .Add(New SqlParameter("@StudentId", SqlDbType.SmallInt, 2)).Value = StudentId .Add(New SqlParameter("@SessionId", SqlDbType.SmallInt, 2)).Value = SessionId .Add(New SqlParameter("@StudentLevel", SqlDbType.VarChar, 10)).Value = StudentLevel .Add(New SqlParameter("@Semester", SqlDbType.VarChar, 10)).Value = Semester .Add(New SqlParameter("@CourseCode", SqlDbType.VarChar, 7)).Value = LisCourseCode.Items.Item(i).ToString .Add(New SqlParameter("@CourseMajorCode", SqlDbType.VarChar, 7)).Value = CourseMajorCode End With objcommand.CommandType = CommandType.StoredProcedure Objcnn.Open() objcommand.ExecuteNonQuery() Objcnn.Close() Next
Also My stored Procedure code is pasted Below:CREATE PROCEDURE STP_STUDENTCOURSEREGISTERED_INSERT1 ( @CourseMajorCode varchar(7), @StudentId int, @StudentLevel varchar(7), @Semester varchar(10), @SessionId int, @CourseCode varchar(7))AS BEGIN INSERT INTO STUDENT_COURSE_RegisteredCourses(StudentId , SessionId,Semester,CourseCode,CourseMajorCode,StudentLevel) VALUES (@StudentId,@SessionId,@Semester,@CourseCode,@CourseMajorCode,@StudentLevel) ENDGO
thanks.Chris