Click here to Skip to main content
15,922,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem in getting data in a textbox from a query, actually its like getting Item_code from Inventory table and the corresponding Unit_Price from related table Inventory_Price

If i write a constant value of Item_Price in the query, the textbox shows the corresponding Unit_Price...I have written this code in the "DropDownClosed" event of combo box:

sql = "Select Unit_Price from Inventory_Price where Item_Code = '10001' AND Ending_Date is null"da= New OleDB.OleDBDataAdapter(sql, connection)da.fill(ds, "Inventory_Price")

Me.Txt_UnitPrice.DataBindings.Add(New Binding("Text", ds, "Inventory_Price.Unit_Price)) 

sql = "Select Unit_Price from Inventory_Price where Item_Code = '10001' AND Ending_Date is null"

da= New OleDB.OleDBDataAdapter(sql, connection)
da.fill(ds, "Inventory_Price")
Me.Txt_UnitPrice.DataBindings.Add(New Binding("Text", ds, "Inventory_Price.Unit_Price))


This code runs correctly....
But i want this....


sql = "Select Unit_Price from Inventory_Price where ITem_Code = '" & combobox.text & "' And Ending_Date is null"

da= New OleDB.OleDBDataAdapter(sql, connection)

da.fill(ds, "Inventory_Price")

Me.Txt_UnitPrice.DataBindings.Add(New Binding("Text", ds, "Inventory_Price.Unit_Price)) 

sql = "Select Unit_Price from Inventory_Price where ITem_Code = '" & combobox.text & "' And Ending_Date is null"

da= New OleDB.OleDBDataAdapter(sql, connection)

da.fill(ds, "Inventory_Price")

Me.Txt_UnitPrice.DataBindings.Add(New Binding("Text", ds, "Inventory_Price.Unit_Price))


Combobox is bind correctly, the list of values are shown in the combobox. here is the code fo combo box bonding:

sql1 = "Select * from Inventory"

da1 = New OleDb.OleDbDataAdapter(sql1, conn)

da1.Fill(ds1, "Inventory")

cmb_ID.DataSource = ds1

cmb_ID.DisplayMember = "Inventory.Item_Code"

cmb_ID.Text = "Select Item Code"
Posted

Personally, I think you are going about this the wrong way. If i were you I would have a Product Class that returns public properties such as Item Code, Unit Price and Ending Date. In this class I would have a shared function that returns a List(of Product) or if you have a lot of products then I would split them into product categories and return a list of product by category. Then in my products management form (which would likely be in a completely different project that references my Products Class) I would have a form level variable i.e
VB.NET
Private Products As List(of Product)
that holds a list(of Product). In my form load I would retrieve the products by calling
VB.NET
Products.GetProducts
I would then bind the ComboBox to the Prodcuts List like this

VB.NET
ComboBox1.DataSource = Products
ComboBox1.DisplayMember = "Product Name"
ComboBox.ValueMember = "Item Code"


then in your
vb.net>ComboBox.SelectedValueChanged</pre>

 
Share this answer
 
v2
Comments
Yasir-Iq 30-May-10 5:05am    
Thanx zim...but actually i have to get those values in the combo box from a database which i have created in MS Access
Actually i havent studied Vb.net in a lot of detail....but i have to make a project....actually this code is correct, as have mentioned it dat it runs correctly but giving a static value.....
Well, if u have any solution for comparing a value in the combobox at run time, do let me kno....
Thanks zim...but actually i have to get those values in the combo box from a database which i have created in MS Access
Actually i haven't studied Vb.net in a lot of detail....but i have to make a project....actually this code is correct, as have mentioned it that it runs correctly but giving a static value.....
Well, if u have any solution for comparing a value in the combobox at run time, do let me know....
 
Share this answer
 
Comments
Christian Graus 30-May-10 17:42pm    
Please don't push 'answer' to make a comment. You know what the word 'answer' means, right ? Your code may work, but it is still crap, take the advice you were given, and if you 'haven't studied VB.NET', consider paying someone who knows how to program to do this if you can't do it properly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900