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

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

>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))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.