Question Specified argument was out of the range of valid values. Parameter name :99

cnboon

New member
Joined
May 18, 2010
Messages
1
Programming Experience
Beginner
I have an input field for a model number with a search button. Once model number is entered and click the search button, the program should display all data accordingly in datagrid for me. However there are some(not all) model will give me error of "Specified argument was out of the range of valid values. Parameter naem :99". Below is my code :
VB.NET:
	Private Sub dlBindData()
        Dim da As SqlDataAdapter

		'==========Query For Master & Detail Rows================== 
        Dim sqlComm As SqlCommand

		'Check if the Model has already been launched
        If blLaunchedModel Then
            sqlComm = New SqlCommand("usp_NPILaunchedDetails")
            sqlComm.CommandType = CommandType.StoredProcedure
            sqlComm.Parameters.Add("@Model", ddlModel.SelectedValue.ToString)

            imgOverallStatus.Src = "images/greendot.gif"
        Else
            'The Model not yet been launched

            '--Get data source ready for Drop Down List in Detail Datagrid:dgNPIDetail --
            'Data bound occured in "Sub dgNPIDetail_ItemDataBound"
            GetDDLSource()

            '--Get Kick Off Date & CP Confirm Date--
            Dim dtKickOff As Date
            Dim dtCPConfirm As Date
            Dim NullCPConfirm As Boolean
            Dim intOverallStatus As Integer

            dtKickOff = CDate(txtKickOffDt.Text)

            If IsDBNull(txtCPConfirmDt.Text) Or txtCPConfirmDt.Text = "" Then
                NullCPConfirm = True
            Else
                dtCPConfirm = CDate(txtCPConfirmDt.Text)
                NullCPConfirm = False
            End If

            sqlComm = New SqlCommand("usp_NPIDetails")
            sqlComm.CommandType = CommandType.StoredProcedure

            sqlComm.Parameters.Add("@Model", ddlModel.SelectedValue.ToString)
            sqlComm.Parameters.Add("@dtKickOff", dtKickOff)

            If NullCPConfirm Then
                Dim sqlDt As SqlDateTime
                sqlDt = SqlDateTime.Null
                sqlComm.Parameters.Add("@dtCPConfirm", sqlDt)
            Else
                sqlComm.Parameters.Add("@dtCPConfirm", dtCPConfirm)
            End If

        End If

        Try
            sqlComm.Connection = DBConnection.OpenConnection
            da = New SqlDataAdapter(sqlComm)
            da.Fill(ds)

            ds.Tables(0).TableName = "Categories"
            ds.Tables(1).TableName = "Tasks"

            dlNPICat.DataSource = ds.Tables("Categories")
            dlNPICat.DataBind()
            dlNPICat.Style.Add("display", "block")
            
            Dim dv As DataView
            '------ Summary Table: General Information ------
            dv = New DataView(ds.Tables("Tasks"))
            dv.RowFilter = "Summary_Section='GenInfo'"
            dv.Sort = "Summary_Task_Seq"

            Dim tblRow As New HtmlTableRow
            Dim cell As New HtmlTableCell
            Dim i As Integer
            Dim j As Integer
            Dim cellPos As Integer
            Dim rowCnt As Integer
            Dim intdvRec As Integer = 0

            tblGenInfo.BgColor = "#EEEEEE"
            tblGenInfo.Border = 0
            tblGenInfo.CellPadding = 4
            tblGenInfo.CellSpacing = 3

            rowCnt = dv.Count
            'Display 3 records per table row
            For i = 0 To Math.Ceiling(rowCnt / 3) - 1
                tblRow = New HtmlTableRow
                For j = 1 To 9
                    'cellPos used to determine record's position in a row
                    cellPos = j Mod 3
                    Select Case cellPos
                        Case 0
                            cell = New HtmlTableCell
                            cell.Width = "140px"
                            cell.BgColor = "#DCDCDC"
                            cell.InnerText = dv(intdvRec).Item("Task_Result").ToString
                            tblRow.Cells.Add(cell)
                            intdvRec += 1
                        Case 1
                            If rowCnt = intdvRec Then
                                Exit For
                            End If
                            cell = New HtmlTableCell
                            cell.Width = "160px"
                            cell.InnerText = dv(intdvRec)("Task").ToString
                            tblRow.Cells.Add(cell)
                        Case 2
                            cell = New HtmlTableCell
                            cell.Width = "10px"
                            cell.InnerText = ":"
                            tblRow.Cells.Add(cell)
                    End Select
                Next
                tblGenInfo.Rows.Add(tblRow)
            Next
            dv.Dispose()

            '------ Summary Table: Technical Information ------
            dv = New DataView(ds.Tables("Tasks"))
            dv.RowFilter = "Summary_Section='TechInfo'"
            dv.Sort = "Summary_Task_Seq"
            dgTechInfo.DataSource = dv
            dgTechInfo.DataBind()
            dv.Dispose()

        Catch ex As Exception
            lblWarning.Text = "Error occured: " & ex.Message
        Finally
            sqlComm.Connection.Close()
        End Try

        hiddlNPICatCount.Value = dlNPICat.Items.Count()

	End Sub
I did a trace using commenting up the lines, and found the line that causing the error to be prompted is at "dlNPICat.DataSource = ds.Tables("Categories")"
If I comment this line up, the error will be gone.
As I am very new to vb.net, can someone give me some expert help?
 
Last edited by a moderator:
Back
Top