存储过程指定了太多参数

时间:2013-08-16 14:36:45

标签: vb.net sql-server-2005 stored-procedures sqldataadapter

我花了一整天的时间在这上面,仍然觉得我没有更接近解决问题(不管它是什么)。我检查并重新检查了数据适配器中的参数和表映射设置。加上数据集字段和代码参数等。该过程旨在填充在数据集“dsStatus”中具有字段“StatusID”和“StatusType”的表。 是声明参数吗? visual studio认为我应该为声明参数提供值吗?感谢任何有建议或解决方案的人!

表格代码......

DsStatus1.Clear()
            DsStatus1 = kernel.getStatus(intDepartmentID, intJobID, "Job")

数据适配器代码......

 Public Function getStatus(ByVal intDepartmentID As Integer, ByVal intJobID As Integer, ByVal strStatusCategory As String) As dsStatus
        Dim dsTemp As New dsStatus
        SqlDataAdapter1.SelectCommand.Parameters("@DepartmentID").Value = intDepartmentID
        SqlDataAdapter1.SelectCommand.Parameters("@JobID").Value = intJobID
        SqlDataAdapter1.SelectCommand.Parameters("@StatusCategory").Value = strStatusCategory
        Me.SqlDataAdapter1.Fill(dsTemp)
        Return dsTemp
    End Function

存储过程......

USE [microgenDB]
    GO
    /****** Object:  StoredProcedure [dbo].[get_job_status]    Script Date: 08/16/2013 15:20:15 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    /* -------------------- */
    ALTER PROCEDURE [dbo].[get_job_status]
    @JobID INT,
    @DepartmentID INT,
    @StatusCategory VARCHAR(50)

    AS

        BEGIN

            DECLARE @MaxJobTaskStartDate DATETIME
            DECLARE @MaxJobTaskEndDate DATETIME

            --Get the most recent task...

            --Get MaxStartDate where EndDate is null
            SELECT     @MaxJobTaskStartDate = MAX(dbo.tbl_JobTask.JobTaskStartDate)
            FROM         dbo.tbl_JobTask INNER JOIN
                                  dbo.tbl_JobDepartmentTask ON dbo.tbl_JobTask.JobDepartmentTaskID = dbo.tbl_JobDepartmentTask.JobDepartmentTaskID INNER JOIN
                                  dbo.tbl_Task ON dbo.tbl_JobDepartmentTask.TaskID = dbo.tbl_Task.TaskID INNER JOIN
                                  dbo.tbl_Job ON dbo.tbl_JobTask.JobID = dbo.tbl_Job.JobID INNER JOIN
                                  dbo.tbl_Status ON dbo.tbl_JobDepartmentTask.StatusID = dbo.tbl_Status.StatusID
            WHERE     (dbo.tbl_JobTask.JobID = @JobID) AND (dbo.tbl_JobTask.JobTaskEndDate IS NULL) AND (dbo.tbl_Status.StatusCategory = @StatusCategory)
            GROUP BY dbo.tbl_JobTask.JobID



            --Get MaxEndDate (for jobs where no task has a null end date)
            SELECT     @MaxJobTaskEndDate = MAX(dbo.tbl_JobTask.JobTaskEndDate)
            FROM         dbo.tbl_JobTask INNER JOIN
                              dbo.tbl_JobDepartmentTask ON dbo.tbl_JobTask.JobDepartmentTaskID = dbo.tbl_JobDepartmentTask.JobDepartmentTaskID INNER JOIN
                              dbo.tbl_Task ON dbo.tbl_JobDepartmentTask.TaskID = dbo.tbl_Task.TaskID INNER JOIN
                              dbo.tbl_Job ON dbo.tbl_JobTask.JobID = dbo.tbl_Job.JobID INNER JOIN
                              dbo.tbl_Status ON dbo.tbl_JobDepartmentTask.StatusID = dbo.tbl_Status.StatusID
            WHERE     (dbo.tbl_JobTask.JobID = @JobID) AND (dbo.tbl_Status.StatusCategory = @StatusCategory)
            GROUP BY dbo.tbl_JobTask.JobID



            --get the max end date coz there's no open tasks
            IF (@MaxJobTaskStartDate IS NULL)
                BEGIN
                        --select the highest order task with the max end date
                    SELECT dbo.tbl_Status.StatusID, dbo.tbl_Status.StatusType
                    FROM         dbo.tbl_Status INNER JOIN
                                          dbo.tbl_JobDepartmentTask ON dbo.tbl_Status.StatusID = dbo.tbl_JobDepartmentTask.StatusID
                    WHERE     (dbo.tbl_JobDepartmentTask.TaskLookupOrder IN
                                          (SELECT     MAX(tbl_JobDepartmentTask_1.TaskLookupOrder) AS MaxTaskLookupOrder
                                            FROM         dbo.tbl_JobDepartmentTask AS tbl_JobDepartmentTask_1 INNER JOIN
                                                                  dbo.tbl_JobTask ON tbl_JobDepartmentTask_1.JobDepartmentTaskID = dbo.tbl_JobTask.JobDepartmentTaskID INNER JOIN
                                                                  dbo.tbl_Status ON tbl_JobDepartmentTask_1.StatusID = dbo.tbl_Status.StatusID
                                            WHERE     (dbo.tbl_JobTask.JobID = @JobID) AND (dbo.tbl_JobTask.JobTaskEndDate = @MaxJobTaskEndDate) AND (dbo.tbl_Status.StatusCategory = @StatusCategory))) AND 
                                          (dbo.tbl_JobDepartmentTask.DepartmentID = @DepartmentID)
                END


            --there is an open task so see if it's start date is later than the closed tasks
            ELSE

                IF @MaxJobTaskStartDate < @MaxJobTaskEndDate
                    BEGIN
                    --use the maxenddate as the task status
                        SELECT dbo.tbl_Status.StatusID, dbo.tbl_Status.StatusType
                        FROM         dbo.tbl_Status INNER JOIN
                                              dbo.tbl_JobDepartmentTask ON dbo.tbl_Status.StatusID = dbo.tbl_JobDepartmentTask.StatusID
                        WHERE     (dbo.tbl_JobDepartmentTask.TaskLookupOrder IN
                                          (SELECT     MAX(tbl_JobDepartmentTask_1.TaskLookupOrder) AS MaxTaskLookupOrder
                                            FROM         dbo.tbl_JobDepartmentTask AS tbl_JobDepartmentTask_1 INNER JOIN
                                                                  dbo.tbl_JobTask ON tbl_JobDepartmentTask_1.JobDepartmentTaskID = dbo.tbl_JobTask.JobDepartmentTaskID INNER JOIN
                                                                  dbo.tbl_Status ON tbl_JobDepartmentTask_1.StatusID = dbo.tbl_Status.StatusID
                                            WHERE     (dbo.tbl_JobTask.JobID = @JobID) AND (dbo.tbl_JobTask.JobTaskEndDate = @MaxJobTaskEndDate) AND (dbo.tbl_Status.StatusCategory = @StatusCategory)))AND 
                                          (dbo.tbl_JobDepartmentTask.DepartmentID = @DepartmentID)
                    END 

                -- use the maxstartdate as the task status
                ELSE
                    BEGIN
                        SELECT dbo.tbl_Status.StatusID, dbo.tbl_Status.StatusType
                        FROM         dbo.tbl_Status INNER JOIN
                                              dbo.tbl_JobDepartmentTask ON dbo.tbl_Status.StatusID = dbo.tbl_JobDepartmentTask.StatusID
                        WHERE     (dbo.tbl_JobDepartmentTask.TaskLookupOrder IN
                                      (SELECT     MAX(tbl_JobDepartmentTask_1.TaskLookupOrder) AS MaxTaskLookupOrder
                                            FROM         dbo.tbl_JobDepartmentTask AS tbl_JobDepartmentTask_1 INNER JOIN
                                                      dbo.tbl_JobTask ON tbl_JobDepartmentTask_1.JobDepartmentTaskID = dbo.tbl_JobTask.JobDepartmentTaskID INNER JOIN
                                                      dbo.tbl_Status ON tbl_JobDepartmentTask_1.StatusID = dbo.tbl_Status.StatusID
                                            WHERE     (dbo.tbl_JobTask.JobID = @JobID) AND (dbo.tbl_JobTask.JobTaskStartDate = @MaxJobTaskStartDate) AND (dbo.tbl_Status.StatusCategory = @StatusCategory)))AND 
                                          (dbo.tbl_JobDepartmentTask.DepartmentID = @DepartmentID)
                    END

    END

定义SqlDataAdapter1的代码(从Visual Studio中的设计器窗口复制) 它在数据映射窗口中显示存储过程的三个表。我尝试将源sp中的所有三个表映射到数据集dsStatus中的一个表,并在数据集中创建三个单独的表,并将每个表映射到存储过程中的相应表。错误信息仍然存在!

  'SqlSelectCommand4
        '
        Me.SqlSelectCommand4.CommandText = "get_job_status"
        Me.SqlSelectCommand4.CommandType = System.Data.CommandType.StoredProcedure
        Me.SqlSelectCommand4.Connection = Me.SqlConnection1
        Me.SqlSelectCommand4.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing), New System.Data.SqlClient.SqlParameter("@JobID", System.Data.SqlDbType.Int, 4), New System.Data.SqlClient.SqlParameter("@DepartmentID", System.Data.SqlDbType.Int, 4), New System.Data.SqlClient.SqlParameter("@StatusCategory", System.Data.SqlDbType.VarChar, 50)})
        '
        'SqlDataAdapter1
        '
        Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand4
        Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table1", "get_job_status", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("StatusID", "StatusID"), New System.Data.Common.DataColumnMapping("StatusType", "StatusType")}), New System.Data.Common.DataTableMapping("Table2", "get_job_status", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("StatusID", "StatusID"), New System.Data.Common.DataColumnMapping("StatusType", "StatusType")}), New System.Data.Common.DataTableMapping("Table", "get_job_status", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("StatusID", "StatusID"), New System.Data.Common.DataColumnMapping("StatusType", "StatusType")})})

1 个答案:

答案 0 :(得分:0)

好的,因为这是因为一个单独的xml文件驻留在运行用户应用程序的本地机器上。即使应用程序中服务器/数据库的连接字符串正确,xml文件连接字符串也指向不同的服务器。因此而2天+2小时。我想你可以猜到我的感受。希望这有助于其他人!