【发布时间】:2019-05-19 01:08:25
【问题描述】:
我使用此代码从数据库中获取名字并将其添加到文本框集合中:
String ConString = "Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = |DataDirectory|\\Database.mdf; Integrated Security = True";
using (SqlConnection con = new SqlConnection(ConString))
{
SqlCommand cmd = new SqlCommand("SELECT Lname,Fname,DDN FROM Staff", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
AutoCompleteStringCollection MyCollection = new AutoCompleteStringCollection();
while (reader.Read())
{
MyCollection.Add(reader.GetString(0));
}
TNom.AutoCompleteCustomSource = MyCollection;
con.Close();
}
自动完成功能有效,但我想获取所选项目的 id 并使用它来填充下面的数据网格视图
【问题讨论】:
标签: c# sql autocomplete windowsformshost