数据库查询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]); } }