1,105,229 Community Members

data manipulation using combobox

Member Avatar
kazekagerandy
Junior Poster in Training
58 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
maurice91
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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
Member Avatar
kazekagerandy
Junior Poster in Training
58 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
maurice91
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

In the combobox SelectedIndexChanged event, also include:

Stocks.Textbox.Text = Stock_Level

Member Avatar
kazekagerandy
Junior Poster in Training
58 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Question Answered as of 1 Year Ago by maurice91
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: