从文本框中的查询中获取价值 [英] Getting value from a query in text box

查看:59
本文介绍了从文本框中的查询中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从查询获取文本框中的数据时遇到问题,实际上就像从库存表获取Item_code和从相关表Inventory_Price获取相应的Unit_Price

如果我在查询中写入Item_Price的常量值,则文本框将显示相应的Unit_Price ...我已在组合框的"DropDownClosed"事件中编写此代码:

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"

推荐答案

就我个人而言,我认为您的做法是错误的.如果我是您,我将拥有一个返回公共属性的产品类,例如项目代码,单价和结束日期.在此类中,我将具有一个共享函数,该函数返回一个List(产品),或者如果您有很多产品,则将它们分为产品类别并按类别返回产品清单.然后在我的产品管理表单中(可能是在完全不同的项目中引用了我的产品类),我将有一个表单级别的变量,即
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
Private Products As List(of Product)

,其中包含列表(产品).在表单加载中,我将通过调用

that holds a list(of Product). In my form load I would retrieve the products by calling

Products.GetProducts

来检索产品,然后将ComboBox绑定到产品列表,例如

I would then bind the ComboBox to the Prodcuts List like this

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



然后在您的



then in your



感谢zim ...但是实际上我必须从MS Access中创建的数据库中的组合框中获取这些值. 实际上我还没有对Vb.net进行过很多详细的研究....但是我必须创建一个项目....实际上,此代码是正确的,正如已经提到的那样,它可以正确运行,但具有静态值. ....
好吧,如果您有任何解决方案可以在运行时比较组合框中的值,请让我知道....
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....


这篇关于从文本框中的查询中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆