We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,623 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

data manipulation using combobox

i am working on a POS as a school project. im having a problem in getting the stocks, which is a record in my database.

this is what i need to do, i need to populate the combobox with drug names with suggests. when i choose a certain drug, its stocks will be displayed on a textbox as a reference.

this is what ive done so far:

Private Sub posform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        accountlbl.Text = mainmenu.namelbl.Text

        dbconnect()
        Dim suggest As New SqlCommand("select prodname from productinfotbl ", connect)
        suggest.CommandType = CommandType.Text

        adapt.SelectCommand = suggest
        adapt.SelectCommand.ExecuteNonQuery()
        adapt.Fill(dset, "suggests")

          ComboBox1.DataSource = dset.Tables("suggests")
        ComboBox1.DisplayMember = "prodname"
        ComboBox1.ValueMember = "prodname"
        ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
        ComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest

i was able to populate the combobox with this but the error strikes when i put this code so i can fetch other data when i change the value of the combobox:

 dbconnect()

        Dim sql As New SqlCommand("select * from  productinfotbl where prodname='" & ComboBox1.Text & "'", connect)
        sql.CommandType = CommandType.Text
        adapt.SelectCommand = sql
        adapt.SelectCommand.ExecuteNonQuery()
        adapt.Fill(dset, "prods")
        dc()

        stocktbx.Text = dset.Tables("prods").Rows(0).Item("stocks")

it shows the ff error message:

An exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll but was not handled in user code

2
Contributors
4
Replies
45 Minutes
Discussion Span
6 Months Ago
Last Updated
7
Views
Question
Answered
kazekagerandy
Junior Poster in Training
54 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

If I understand you correctly, when the combobox is set to a certain drug, you want the stocks corresponding to that drug to be stored in a textbox.

Here is a solution:

'Create a dataview
dim dv as new dataview

'Associate the dataview to dst (Dataset table)
dv.Table = dst.Tables("Drugs")

'Data Row View object to query DataView object
Dim drv As DataRowView 

'Filter based on a combo box value selected
dv.RowFilter = "[Drug ID] = " & CInt(cboComboBox.SelectedValue)


'Retrieve my values returned in the result
For Each drv In dv
     Stock_Level = drv("Stocks") 
Next
maurice91
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0

thanks for the suggestion maurice, but my question is this: where should i put that code? i mean, which event?

kazekagerandy
Junior Poster in Training
54 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

In the combobox SelectedIndexChanged event, also include:

Stocks.Textbox.Text = Stock_Level

maurice91
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0

oh thanks maurice! that really saved me! :))

kazekagerandy
Junior Poster in Training
54 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 6 Months Ago by maurice91

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0701 seconds using 2.67MB