我在文本框上输入一个值,在数据库中与该值相关的其他数据自动的显示在其他的标签上。asp.net

2024-11-19 20:26:08
推荐回答(2个)
回答1:

string selectStr = "select name from base_customers";
OleDbCommand mycommand = new OleDbCommand(selectStr, myconn);

DataSet myDataSet = new DataSet();
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();

myDataAdapter.SelectCommand =
new OleDbCommand(selectStr, myconn);
OleDbCommandBuilder builder =
new OleDbCommandBuilder(myDataAdapter);

myDataAdapter.Fill(myDataSet, "customers");

string[] arr = new string[myDataSet.Tables["customers"].Rows.Count];

for (int i = 0; i < arr.Length; i++)
{
arr[i] = myDataSet.Tables["customers"].Rows[i][0].ToString();
}

textBox1.AutoCompleteCustomSource.AddRange(arr);

这是像百度的那样,匹配的会显示在文本框下面,测试通过的

回答2:

文本框有个TextChanged事件,注册这个事件后在里面 写代码连接数据库进行查询,然后把查询到的值赋给其它标签。