我很友好地被困在这里,我只是找不到解决这个问题的方法。
我的本地数据库是VistaDB。我的代码在前10个结果中有效,但我需要收集“Pojam”列中的所有内容以显示在文本框中,而不仅仅是前10个结果。
我的代码在text_changed事件处理程序
中运行请帮忙。提前致谢
string pojam = UppercaseFirst(TextBoxPojam.Text.ToLower());
AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
VistaDBConnection con = new VistaDBConnection(@"data source='|DataDirectory|Recnik.vdb4';Pooling=true;Open Mode = NonexclusiveReadWrite;");
con.Open();
VistaDBCommand cmnd = con.CreateCommand();
cmnd.CommandType = CommandType.Text;
cmnd.CommandText = "SELECT top(10) Pojam FROM dbo.RecnikFinal";
VistaDBDataReader dReader;
dReader = cmnd.ExecuteReader();
if (dReader.Read())
{
while (dReader.Read())
namesCollection.Add(dReader["Pojam"].ToString());
}
else
{
MessageBox.Show("Data not found");
}
dReader.Close();
TextBoxPojam.AutoCompleteMode = AutoCompleteMode.Suggest;
TextBoxPojam.AutoCompleteSource = AutoCompleteSource.CustomSource;
TextBoxPojam.AutoCompleteCustomSource = namesCollection;
答案 0 :(得分:3)
替换以下行:
cmnd.CommandText = "SELECT top(10) Pojam FROM dbo.RecnikFinal";
与
cmnd.CommandText = "SELECT Pojam FROM dbo.RecnikFinal";