0

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...

Code:

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))

Combobox is bind correctly, the list of values are shown in the combobox....

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
5
Replies
8
Views
7 Years
Discussion Span
Last Post by __avd
0

the combo box in the SQL statement is wrong.

it should read:

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

I hope this helps

Edited by detoxx: n/a

0

>Combobox is bind correctly, the list of values are shown in the combobox...

Check the combobox values. Can you please post combobox bind code?

0

Even this query does not work....i've already tried with SelectedItem property of the combobox....

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

binding combobox

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"
0
sql = "Select Unit_Price from Inventory_Price where ITem_Code=@itemcode And Ending_Date is null"
Dim cmd as new OleDBCommand(sql,connection)
cmd.Parameters.AddWithValue("@itemcode",cmb_ID.Text)

da= New OleDB.OleDBDataAdapter(cmd)
da.fill(ds, "Inventory_Price")
Me.Txt_UnitPrice.DataBindings.Add(New Binding("Text", ds, "Inventory_Price.Unit_Price))
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.