AutoCompleteCustomSource (or) AutoCompleteStringCollection

public AutoCompleteStringCollection GetDbname(String Host, string usrname, string pwd)
{


try{
if (Host != ""){
usrname =
"ffuserAdmin";pwd =
"Admin1234";
AutoCompleteStringCollection Database = new AutoCompleteStringCollection();
SqlConnection _conG = new SqlConnection("Server =" + Host+
"; User ID =" + usrname+
"; Password =" + pwd+
"; Trusted_Connection =False;");_conG.Open();

SqlDataAdapter ada = new SqlDataAdapter("Select * from Sys.DataBases where name like 'Sy%'", _conG);
DataTable dt = new DataTable();ada.Fill(dt);

foreach (DataRow dr in dt.Rows){
Database.Add(dr[
"name"].ToString());}

return Database;_conG.Close();
}
}

catch (Exception ex){

throw ex;}

return null;}


private void Host_Leave_1(object sender, EventArgs e){

Process pr = new Process();
try{
catalogDb.AutoCompleteCustomSource = pr.GetDbname(Host.Text.Trim(),
"", "");}

catch (Exception ex){

MessageBox.Show(ex.Message, "DataBase ", MessageBoxButtons.OK, MessageBoxIcon.Information);}
}

Comments