Specified argument was out of the range of valid values

R

rhepsi

Hi All...

I Came across this error while populating a combobox from
a datatable (I'm working in VB.NET):

Specified argument was out of the range of valid values.
Parameter name: '-1' is not a valid value
for 'index'


code[VB]

Private Sub PopulatePrManagerCombo()
' This procedure populates the combo box on the
' form with a list of Project Manager from the
' Dms database.

Dim cnSQL As MySqlConnection
Dim cmSQL As MySqlCommand
Dim drSQL As MySqlDataReader
Dim strSQL As String
Dim objListItem As ListItem



Try
' Build Select statement to query Project Manager Name from the Staff
' table.

strSQL = "SELECT tbl_staffs.stf_first_name, " _
& " tbl_staff_assignments.sta_staff_id_fk " _
& " FROM tbl_staffs ,tbl_staff_assignments " _
& " WHERE tbl_staffs.stf_staff_id_pk = tbl_staff_assignments.sta_staff_id_fk
" _
& " AND tbl_staff_assignments.sta_category_id_fk = 1 order by tbl_staffs.
stf_first_name"

cnSQL = New MySqlConnection
cnSQL.ConnectionString = connect.ConnectionString
cnSQL.Open()

cmSQL = New MySqlCommand(strSQL, cnSQL)
drSQL = cmSQL.ExecuteReader()

cboPrMgr.Items.Clear()

' Loop through the result set and add the category
' names to the combo box.
Do While drSQL.Read()

objListItem = New ListItem(drSQL.Item("stf_first_name").ToString(), _
Convert.ToInt32(drSQL.Item("sta_staff_id_fk")))
cboPrMgr.Items.Add(objListItem)


Loop

' Close and Clean up objects
drSQL.Close()
cnSQL.Close()
cmSQL.Dispose()
cnSQL.Dispose()

Catch e As MySqlException

MsgBox("To run this sample you must have MySql Access" & _
" For instructions on " & _
"installing contact Admin.", MsgBoxStyle.Critical, _
"MySql not found")
' Quit program if connection method was not successful.
'End


Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")
End Try


End Sub


plz help me out...


thnx n regards
hepsi
 
J

Jan Hyde (VB MVP)

Hi All...

I Came across this error while populating a combobox from
a datatable (I'm working in VB.NET):

Specified argument was out of the range of valid values.
Parameter name: '-1' is not a valid value
for 'index'

I'd guess your trying to set the index of the item to -1
which isn't valid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top