iamme

I'm still trying to figure out how to get selectedindex of combobox1 to retrieve only certain information from SQL. I still think it's easier for me to just do

Select Column From Table Where (certain row item)

but for some reason this doesn't work. WHY Am I missing something I understand the statement, but I don't know how to get it to work. You know how the program automatically detects the language and highlights it in blue, well it doesn't do that for "From" and "Where". WHY If someone can answer that, I'd appreciate it.

So anyways, I took a different route and now I get the message

"Argument Exception was Unhandled: Cannot bind to the property 'Food Components' on the target control.
Parameter name: PropertyName"

Here's the code I used (highlighted code is where I get error):

Private Sub Food_ComponentsComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Food_ComponentsComboBox.SelectedIndexChanged

With Me.Food_ComponentsComboBox

.Items.Add("Milk")

.Items.Add("Fruits/Vegetables")

.Items.Add("Meats")

.Items.Add("Grains/Breads")

End With

If Food_ComponentsComboBox.SelectedItem = "Milk" Then

With Me.Food_Item_as_PurchasedComboBox

.Items.Clear()

.DataSource = Me.USDADatabaseDataSet.USDA

.DataBindings.Add("Food Components", Me.USDADatabaseDataSet.USDA.Columns, "Milk", True)

.DisplayMember = "Food Item as Purchased"

.ValueMember = "Food Components"

End With

End If

End Sub

Sorry for being so dumb at this, and any help is greatly appreciated.



Re: Visual Basic Express Edition Still stuck!

iamme

P.S. Can anyone explain

.databindings.add(what does this do, what does this do, what does this do, what's this for )

Thanks!





Re: Visual Basic Express Edition Still stuck!

pinoyz

hi there!!.... i'm still new in this stuff... your problem is.. data in the database and place it to combobox

"onload even form1"

dim theconnectionstring as new oledb.oledbconnection("connectionstring")

dim sqlcommand as new oledb.oledbcommand("select * from table_name",connectionstring)

dim adapter as new oledb.oledbadapter(sqlcommand)

dim dt as new datatable()

sqlcommand.connection.open()

adapter.fill(dt)

combobox1.valuemember = "column_name"

combobox1.datasource= dt

sqlcommand.connection.close()

i hope it helps






Re: Visual Basic Express Edition Still stuck!

pinoyz

oh ok... i done this..before.... i done this by providing a parameter

for example:

dim sqlcommand as new oledb.oledbcommand("select * from table where MEAT = @combo1",connectionstring)

your database table must contain 2 columns...for example

column1          column2

MEAT             CHICKEN

MEAT                BEEF

MEAT              PORK

VEGIES          BROCOLLI

VEGIES         TURNIP

FRUIT            MANGO

FRUIT           TOMATO

dim theconnectionstring as new oledb.oledbconnection("connectionstring")

dim sqlcommand as new oledb.oledbcommand("select DISTINCT * from table_name" where MEAT = @combo1,connectionstring)

dim combo00 as new oledb.oledbparameter("@combo1",oledbtype.varchar, 50)

combo00.value = combo1.Text

sqlcommand.parameters.add(combo00)

dim adapter as new oledb.oledbadapter(sqlcommand)

dim dt as new datatable()

sqlcommand.connection.open()

adapter.fill(dt)

combobox2.valuemember = "column_name"   ' in your case column2

combobox2.datasource= dt

sqlcommand.connection.close()

 

 

 

 

 

 

 

 

 

 






Re: Visual Basic Express Edition Still stuck!

iamme

Thanks Pinoyz, but that's not my problem. What I'm trying to do is, when you select an item in one combobox the second combobox should only retrieve information from the database table USDA that pertains to the selected item. For example, if you choose "Meat" in the first combobox, the second combobox should only retrieve "Chicken", "Beaf", "Pork", "Beans", etc. If they choose fruits/vegetables, then the second combobox should have "Apples", "Oranges", "Lettuce", "Onions", etc. And so on. So far it seems I'm understanding what I'm doing, but I can't figure out how to get that ".databindings.add()" to work. What's supposed to go into the () All I know is this .databindings.add( , datasource.table, , T/F)

I think it means .databindings.add(Table Column, datasource.table, row, if true then get if false then take an action (i.e. delete, move))

Am I right Please correct me if I'm wrong.





Re: Visual Basic Express Edition Still stuck!

pinoyz

oh ok... i done this..before.... i done this by providing a parameter

for example:

dim sqlcommand as new oledb.oledbcommand("select * from table where MEAT = @combo1",connectionstring)

your database table must contain 2 columns...for example

column1 column2

MEAT CHICKEN

MEAT BEEF

MEAT PORK

VEGIES BROCOLLI

VEGIES TURNIP

FRUIT MANGO

FRUIT TOMATO

dim theconnectionstring as new oledb.oledbconnection("connectionstring")

dim sqlcommand as new oledb.oledbcommand("select DISTINCT * from table_name" where MEAT = @combo1,connectionstring)

dim combo00 as new oledb.oledbparameter("@combo1",oledbtype.varchar, 50)

combo00.value = combo1.Text

sqlcommand.parameters.add(combo00)

dim adapter as new oledb.oledbadapter(sqlcommand)

dim dt as new datatable()

sqlcommand.connection.open()

adapter.fill(dt)

combobox2.valuemember = "column_name" ' in your case column2

combobox2.datasource= dt

sqlcommand.connection.close()