Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with some list boxes

Status
Not open for further replies.

RiverGuy

Programmer
Jul 18, 2002
5,011
US
Hi. I'm writing this in VB.Net.

This is the scenario:

A user makes some choices via a couple textboxes and a drop down list.

He or she presses a button.

The button fires a procedure to an SQL Server to call a stored procedure.

Parameters are passed to the stored procedure from the textboxes and the drop down list, as well as some constants.

What is happening is that the values from the drop down list are being taken from the first item in the list--not the selected one. I have this same scenario in another spot in my project, but it works there. I cannot get it to work here and they seem the same. Can anyone offer some help?

Heres the code....Thanks


Private Sub addItems()
'Add an Item
With cmdAddItems
.Connection = conxxx
.CommandType = CommandType.StoredProcedure
.CommandText = "xxxxxx"
With cmdAddItems.Parameters
.Add("@ID", TextBox1.Text)
.Add("@Num", listItems.SelectedItem.Value)
.Add("@Description", listItems.SelectedItem.Text)
.Add("@xxx", "none")
.Add("@Qty", txtQty.Text)
.Add("@Price", 2.5)
End With
End With

cmdAddItems.ExecuteScalar()
End Sub
 
Most likely, you have a duplicate value in your listbox. That will cause this behavior. The only fix is to ensure that all dropdownlist values are unique.
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Thanks. I got rid of all duplicates, and that was not it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top