我正在尝试使用数据库中的值自动完成文本框。当我进行子弹测试时,代码将一直运行,直到if
下面函数中的语句。有人可以告诉我为什么我的代码在那之后不会执行if
吗?
我正在尝试运行以下命令,但它一直在之前跳出if
:
public AutoCompleteStringCollection AutoCompleate(string dataBase, string procedure)
{
AutoCompleteStringCollection namesCollection =
new AutoCompleteStringCollection();
SqlDataReader dReader;
SqlCommand cmd = new SqlCommand(procedure, con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
dReader = cmd.ExecuteReader(); // This is the last place my bullet check
// gets before it hop's out!
if (dReader.HasRows == true)
{
while (dReader.Read())
namesCollection.Add(dReader["SystemUser"].ToString());
}
con.Close();
dReader.Close();
return namesCollection;
}
附加信息,但请关注以上内容!
请询问您是否需要任何信息。:)
对上述的呼吁:
textBoxUser.AutoCompleteMode = AutoCompleteMode.Suggest;
textBoxUser.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBoxUser.AutoCompleteCustomSource =
DatabaseService.Instance.AutoCompleate("AuditIT", "AutoCompleate");
存储过程:
USE [AuditIT]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Allow textboxs to have a autocomplete
ALTER procedure [dbo].[AutoCompleate]
as
Select distinct SystemUser from SchemaAudit
order by SystemUser asc