【发布时间】:2016-08-11 02:32:46
【问题描述】:
我使用 Visual Studio C# 并使用 Access 作为我的数据库。我有两列,ItemCode 和 ProductName。我想在选择其itemcode时自动在其TextBox上自动输入。我怎样才能做到这一点?
一些代码:
try
{
con.Open();
OleDbCommand command = new OleDbCommand(@"Select * from TblInventory where ItemCode='" + txtItem.Text + "'");
command.Connection = con;
command.Parameters.AddWithValue("itemcode", txtItem.Text);
OleDbDataReader reader = command.ExecuteReader();
if (reader.Read())//Update Item Code is already exist
{
.........
请随意编辑我的问题,请善待。谢谢各位
【问题讨论】:
-
你的意思是在选择itemcode时自动输入productname,我希望你想更新product_name对应
where子句中的id,不是吗? -
是的,我想获取产品名称的值并在我的文本框中调用它,该文本框对应于该项目代码的同一行
-
我会至少将 ItemCode 和 ProductName 对加载到 DataTable,然后将 bind DataTable 加载到您用于显示和选择 itemcode 和 productname 的任何控件中。请记住,您可以绑定one data source to multiple controls。根据需要为每个控件调整 DisplayMember。
标签: c# ms-access visual-studio-2012