Using system. data. sqlclient; </P> <p> /// <summary> <br/> // obtain the names of all database servers in the LAN. <br/> /// </Summary> <br/> // <returns> server name array </returns> <br/> public list <string> getsqlservernames () <br/> {<br/> datatable datasources = sqlclientfactory. instance. createperformanceenumerator (). getdatasources (); </P> <p> datacolumn column = CES. columns ["instancename"]; <br/> datacolumn column2 = CES. colum NS ["servername"]; </P> <p> datarowcollection rows = CES. rows; <br/> List <string> serverlist = new list <string> (); <br/> String Array = string. empty; <br/> for (INT I = 0; I <rows. count; I ++) <br/>{< br/> string str2 = rows [I] [column2] as string; <br/> string STR = rows [I] [column] as string; <br/> If (STR = NULL) | (Str. length = 0) | ("MSSQLServer" = Str) <br/>{< br/> array = str2; <Br/>}< br/> else <br/> {<br/> array = str2 + @ "/" + STR; <br/>}</P> <p> serverlist. add (array); <br/>}</P> <p> serverlist. sort (); </P> <p> return serverlist; <br/>}</P> <p> // <summary> <br/> // query non-system databases in SQL <br/> /// </Summary> <br/> // <Param name = "connection"> </param> <br/> // <returns> </returns> <br/> public list <string> databaselist (string connection) <br/>{< br/> List <string> getcatali St = new list <string> (); <br/> string explain stirng = "Select name from sys. databases where database_id> 4 "; <br/> sqlconnection connect = new sqlconnection (connection); <br/> sqlcommand cmd = new sqlcommand (begin stirng, connect ); <br/> try <br/> {<br/> If (connect. state = connectionstate. closed) <br/>{< br/> connect. open (); <br/> idatareader DR = cmd. executereader (); <br/> getcatalist. clear (); <br/> While (dr. read () <br/>{< br/> getcatalist. add (Dr ["name"]. tostring (); <br/>}< br/> dr. close (); <br/>}</P> <p >}< br/> catch (sqlexception e) <br/>{< br/> // MessageBox. show (E. message); <br/>}< br/> finally <br/>{< br/> If (connect! = NULL & connect. state = connectionstate. open) <br/>{< br/> connect. dispose (); <br/>}< br/> return getcatalist; <br/>}</P> <p> // <summary> <br/> // obtain the column name <br/> /// </Summary> <br />/// <Param name = "connection"> </param> <br/> /// <returns> </returns> <br/> public list <string> gettables (string connection) <br/>{< br/> List <string> tablelist = new list <string> (); <br/> sqlconnection objc Onnetion = new sqlconnection (connection); <br/> try <br/> {<br/> If (objconnetion. state = connectionstate. closed) <br/>{< br/> objconnetion. open (); <br/> datatable objtable = objconnetion. getschema ("tables"); <br/> foreach (datarow row in objtable. rows) <br/>{< br/> tablelist. add (row [2]. tostring ()); <br/>}< br/> catch <br/>{</P> <p >}< br/> finally <br />{< br/> If (objconneti On! = NULL & objconnetion. state = connectionstate. closed) <br/>{< br/> objconnetion. dispose (); <br/>}</P> <p >}< br/> return tablelist; <br/>}</P> <p> // <summary> <br/> // obtain a field <br/> /// </Summary> <br />/// <Param name = "connection"> </param> <br/> /// <Param name = "tablename"> </param> <br/> /// <returns> </returns> <br/> public list <string> getcolumnfield (string connection, string tablename) <br/>{< br/> List <string> columnlist = new list <string> (); <br/> sqlconnection objconnetion = new sqlconnection (connection ); <br/> try <br/>{< br/> If (objconnetion. state = connectionstate. closed) <br/>{< br/> objconnetion. open (); <br/>}</P> <p> sqlcommand cmd = new sqlcommand ("Select name from syscolumns where id = object_id ('" + tablename + "') ", objconnetion); <br/> sqldatareader objreader = cmd. executereader (); </P> <p> while (objreader. read () <br/>{< br/> columnlist. add (objreader [0]. tostring ()); </P> <p >}< br/> catch <br/>{</P> <p >}< br/> objconnetion. close (); <br/> return columnlist; <br/>}< br/>