0
我想有一個文本框自動完成從數據庫值。當我子彈測試的代碼將走,但直到在下面的函數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
你如何定義你的''SqlConnection' con'? –
如果它「跳出」,則意味着拋出異常。你有沒有嘗試在調試器中運行代碼?您是否在此代碼之外使用異常處理程序? –
@AlexR。 con = new SqlConnection(Properties.Settings.Default.DBConnectionString.ToString());連接字符串的工作,我有其他的功能做了同樣的方式:) – Pomster