1 /// <summary>2 ///get all database names for the target server3 /// </summary>4 /// <param name= "ServerName" ></param>5 /// <param name= "UserName" ></param>6 /// <param name= "password" ></param>7 Public voidGetdatabasenamelist (stringServerName,stringUserName,stringpassword)8 {9SQLDMO. Application Sqlapplication =NewSQLDMO. ApplicationClass ();TenSQLDMO. SQL Server SQL Server =NewSQLDMO. Sqlserverclass (); One ASqlserver.connect (serverName, userName, password);//connecting to a server - - foreach(SQLDMO. Database Databbaseinchsqlserver.databases) the { - if(Databbase.name! =NULL) - { - This. DATABASETREEVIEW.NODES.ADD (databbase.name); + - getdatabasetablelist (serverName, userName, password, databbase.name); + } A } at } - - - /// <summary> - ///loading tables in the database - /// </summary> in /// <param name= "ServerName" >Server name</param> - /// <param name= "UserName" >User name</param> to /// <param name= "password" >Password</param> + /// <param name= "DataBaseName" >Database name</param> - Private voidGetdatabasetablelist (stringServerName,stringUserName,stringPasswordstringdataBaseName) the { *SQLDMO. SQL Server =NewSQLDMO. Sqlserverclass (); $ Panax Notoginseng //Connect to Server - Server.connect (serverName, userName, password); the + //for all database traversal, get the specified database A for(inti =0; i < Server.Databases.Count; i++) the { + //determines whether the current database is a specified database - if(Server.Databases.Item (i +1,"dbo"). Name = =dataBaseName) $ { $ //get the specified database -Sqldmo._database db = Server.Databases.Item (i +1,"dbo"); - the //get all tables in the specified database - for(intj =0; J < Db. Tables.count; J + +)Wuyi { the This. Databasetreeview.nodes[i]. Nodes.Add (db. Tables.item (j +1,"dbo"). Name); - } Wu } - } About } $ - - /// <summary> - ///get all column names in the table A /// </summary> + /// <param name= "ServerName" >Server name</param> the /// <param name= "UserName" >User name</param> - /// <param name= "password" >Password</param> $ /// <param name= "TableName" >Table name</param> the /// <param name= "DataBaseName" >Database name</param> the /// <returns></returns> the Public stringGetrowlistfromtable (stringServerName,stringUserName,stringPasswordstringTableName,stringdataBaseName) the { - stringresult =string. Empty; in the stringConnectionString =string. Empty; theConnectionString + ="server="+ServerName; AboutConnectionString + ="; Pwd="+password; theConnectionString + ="; Uid="+UserName; theConnectionString + =";D atabase="+DataBaseName; the + stringCommandString =string. Empty; -CommandString + ="select name from syscolumns where id=object_id ('"; theCommandString + =TableName;BayiCommandString + ="')"; the the -SqlConnection SqlConnection =NewSqlConnection (connectionString); -SqlCommand SqlCommand =NewSqlCommand (CommandString, sqlConnection); the theSqlDataAdapter dataAdapter =NewSqlDataAdapter (CommandString, sqlConnection); the theDataSet DataSet =NewDataSet (); - DataAdapter.Fill (dataSet); the theDataTable datatable = dataset.tables[0]; the 94 //datatable datatable = Sqlconnection.getschema ("Tables"); the foreach(DataRow rowinchdatatable.rows) the { theResult + = row[0]. ToString () +"-";98 } About - if(Result! =NULL)101 {102 returnresult; 103 }104 Else the {106 return "0";107 }108}