数据库查询Database中的表

 public class UserDA
    {
         
         SqlConnection conn;
         SqlCommand cmd;
         public UserDA(Use uuu)
         {
             conn =new SqlConnection( "server=" + uuu.Server + ";database=" + uuu.Database + ";user=" + uuu.User + ";pwd=" + uuu.Pwd);
             cmd = conn.CreateCommand();
         }
 public ArrayList Table(string database)
         {
             cmd.CommandText = "Select TABLE_NAME FROM "+database+".INFORMATION_SCHEMA.TABLES Where TABLE_TYPE='BASE TABLE' ";
             conn.Open();
             SqlDataReader dr = cmd.ExecuteReader();
             string a = null;
             if (dr.HasRows)
             {
                 while(dr.Read())
                 {
                     a = dr["TABLE_NAME"].ToString();
                     al.Add(a);
                 }
             }
             cmd.Dispose();
             conn.Close();
             return al;
}
    public partial class Form2 : Form
    {
        private Use UUU;
        public Form2(Use uuu)
        {
            InitializeComponent();
            UUU = uuu;
        }

        private void Form2_Load(object sender, EventArgs e)           
        {
            ArrayList aaa = new UserDA(UUU).Table(UUU.Database);
            for (int y = 0; y < aaa.Count; y++)
            {  
                comboBox1.Items.Add(aaa[y]);            
            }
        }

 

posted @ 2015-07-19 22:04  SaYes  阅读(341)  评论(0编辑  收藏  举报