473,385 Members | 1,387 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,385 software developers and data experts.

Specified argument was out of the range of valid values

111 100+
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..
Jun 29 '07 #1
6 3666
kenobewan
4,871 Expert 4TB
Did you get a line number for that error?
Jun 30 '07 #2
rhepsi
111 100+
Did you get a line number for that error?
Hii,

The error must be at :
[ERROR]
cmSQL.Parameters.Add("?Pr_ManagerID", CType(cboPrMgr.Items(cboPrMgr.SelectedIndex), ListItem).ID)........[ERROR]

And moreover when im tryign to clear the form:
[vb code]

Private Sub ClearForm()

' Clear the data entry form.


txtPrCode.Text = ""
txtPrLocation.Text = ""
---------- cboPrMgr.SelectedIndex = -1 ---------------------
txtPrStreet.Text = ""
cboState.SelectedIndex = -1

[/vb code]


cboPrMgr.SelectedIndex= -1 ..... i have a doubt here whther this is correct or not???

plz help..

thnx in advance
Jul 2 '07 #3
kenobewan
4,871 Expert 4TB
Why is there a question mark in front of ?Pr_ManagerID? I generally associate -1 with JS have you tried null?
Jul 2 '07 #4
rhepsi
111 100+
Why is there a question mark in front of ?Pr_ManagerID? I generally associate -1 with JS have you tried null?

Thnx for ur reply...

Yes ive tried null but of no use...

1 thing i observed is: few records are being displayed from the combo bx without this error whereas other records are displaying error message.
Jul 3 '07 #5
kenobewan
4,871 Expert 4TB
Only thing I can think of is that they are not all in the right format. This is the same error "Parameter name: '-1' is not a valid value". Then try and debug, leave out this parameter and see if the page works. After that write out the value to see what you get. HTH.
Jul 3 '07 #6
rhepsi
111 100+
Only thing I can think of is that they are not all in the right format. This is the same error "Parameter name: '-1' is not a valid value". Then try and debug, leave out this parameter and see if the page works. After that write out the value to see what you get. HTH.
hii,

hey ive done tht tooo...
nw im thinking abt this line...

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

is there any problem here: Convert.ToInt32
Jul 3 '07 #7

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

Similar topics

3
by: Michael Conroy | last post by:
Hi... Synposis... Throws exception: "Specified argument was out of the range of valid values." Read on for the juicy tidbits. MySimpleClassCol mscc=new MySimpleClassCol(); private void...
4
by: Todd Perkins | last post by:
Hello all, surprisingly enough, this is my first newsgroup post, I usually rely on google. So I hope I have enough info contained. Thank you in advance for any help! Problem: I am getting...
9
by: subdhar | last post by:
I'm getting following error in asp.net application.I search the web and couldn't find error like this can any one help me in trouble with this error Specified argument was out of the range of...
0
by: darrel | last post by:
What does this error mean? Specified argument was out of the range of valid values. Parameter name: value System.Web It's being thrown here: DDL_SubCategory.Enabled = True...
0
by: rajarameshvarma | last post by:
Hi.... I have a serious problem while deploying my asp.net application. I have developed a web project in which everypage contains Header, Left navigation and footer as usercontrols. For center...
1
by: IndiraPriyaDarshini | last post by:
Hi , Am trying to sum the total in the footer if a gridview, but am getting the error "Specified argument was out of the range of valid values. Parameter name: index "..Its Printing one cell value...
0
by: gsauns | last post by:
I have a DetailsView which is inside of a FormView. I lifted this DetailsView straight off another one of my pages, where it was working beautifully. Now I get this endlessly frustrating error...
2
by: Chapi | last post by:
hi, i'm having problems with a datagrid paging. it's populates fine, but when i click the paging button appears this error:"Specified argument was out of the range of valid values.Parameter name:...
1
by: RN1 | last post by:
I have a DataGrid with 7 BoundColumns. A user can login as an admin or non-admin. When a user logs in as a non-admin & the DatGrid is in the editable mode, I want only the first 4 columns i.e. the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.