Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当在另一个文本框中输入数据时,文本框完成_C#_.net_Database_Winforms_Ms Access - Fatal编程技术网

C# 当在另一个文本框中输入数据时,文本框完成

C# 当在另一个文本框中输入数据时,文本框完成,c#,.net,database,winforms,ms-access,C#,.net,Database,Winforms,Ms Access,假设我的表单上有两个TextBox 如您所见,我必须在第一个输入主键,并且我希望第二个文本框显示与此键对应的字段值 我正在使用Access 2016,我们可以这样考虑我的桌子: +----------+--------+------+---------+ | Field | Type | Null | Key | +----------+--------+------+---------+ | Item | Number | NO | PRIMARY | | Pr

假设我的表单上有两个
TextBox

如您所见,我必须在第一个输入主键,并且我希望第二个
文本框
显示与此键对应的字段值

我正在使用Access 2016,我们可以这样考虑我的桌子:

+----------+--------+------+---------+
| Field    | Type   | Null | Key     |
+----------+--------+------+---------+
| Item     | Number |  NO  | PRIMARY |
| Provider | Text   |  YES |         |
+----------+--------+------+---------+
这是我的问题:是否可以显示带有
数据绑定属性的提供者字段?否则,您将如何实现这一目标?

C#

正如第页所述,Pat已经提到,您可以使用一个简单的SELECT查询。大概是这样的:

cn.Open(); //open connection
string comm = "SELECT Provider From table WHERE Item = @Item";
cmd = new SqlCeCommand(comm, cn);
cmd.Parameters.Add("@Item", SqlDbType.NVarChar, 100).Value = textbox1.Text;

textbox2.Text = cmd.ExecuteScalar(); //get first row with the right item
cn.Close(); //close connection
现在你的私密者在文本框2中

你也可以直接查

请注意:上面的例子我已经记不清了。未测试。

我解决了我的问题

private void textBoxItem_TextChanged(object sender, EventArgs e)
{
    int item;
    var row;

    if (int.TryParse(textBoxItem.Text, out item))
    {
        row = dataSet.PROVIDERS.FindByitem(item);

        if (row != null)
            textBoxProvider.Text = row.provider;
    }
}

一个简单的
select
query和
datareader
来填充文本框是一种方法。是的,你们都是对的。但我想要实现的不是质询的基础。