I just wrote a small program to implement the automatic prompt function of the C # text box. I feel pretty good to share with you.
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. Data. sqlclient;
Namespace text box smart prompt
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private void form1_load (Object sender, eventargs E)
{
String STR = "";
// Sqlconnection conn = new sqlconnection ();
// Conn. connectionstring = "Server = 10.68.69.203, 81; database = cpudata; user id = sa; Password = 19790601 ";
// Conn. open ();
// Sqlcommand cmd = new sqlcommand ();
// Cmd. commandtext = "select user_china_name from user_info ";
// Cmd. Connection = conn;
// Sqldataadapter da = new sqldataadapter (CMD );
// Dataset DS = new dataset ();
// Da. Fill (DS );
// Foreach (datarow DR in DS. Tables [0]. Rows)
//{
// STR + = "," + Dr ["user_china_name"];
//}
// Conn. Close ();
// STR = Str. substring (1 );
// This. textbox1.autocompletecustomsource. addrange (Str. Split (','));
Autocompletestringcollection ACSC = new autocompletestringcollection ();
Sqlconnection conn = new sqlconnection ();
Conn. connectionstring = "Server = 10.68.69.203, 81; database = cpudata; user id = sa; Password = 19790601 ";
Conn. open ();
Sqlcommand cmd = new sqlcommand ();
Cmd. commandtext = "select user_china_name from user_info ";
Cmd. Connection = conn;
Sqldatareader DR = cmd. executereader ();
While (dr. Read ())
{
ACSC. Add (Dr [0]. tostring ());
}
Dr. Close ();
Conn. Close ();
This. textbox1.autocompletemode = system. Windows. Forms. autocompletemode. Suggest;
This. textbox1.autocompletesource = system. Windows. Forms. autocompletesource. customsource;
This. textbox1.autocompletecustomsource = ACSC;
}
}
}