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 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

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 6 Years Ago by detoxx: n/a

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

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

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"

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"
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 article has been dead for over six months. Start a new discussion instead.