日期:2014-05-17  浏览次数:20910 次

获取sql数据库中所有的表名并显示在窗口中
从空间下拉框选择数据库,显示该数据库中所有的表名信息(sqlserver)

------解决方案--------------------
SqlConnection cn = new SqlConnection();
 cn.ConnectionString = “Data Source=SQLSERVER;Initial Catalog=DB1;Persist Security Info=True;User ID=test;Password=pas”;
 cn.Open();
 
SqlCommand command          = new SqlCommand();
 command.Connection = cn;
 
 command.CommandText = “exec sp_tables @table_type =¥”‘TABLE’¥”";
 SqlDataAdapter adp = new SqlDataAdapter(command);
 DataTable objRs = new DataTable();
 adp.Fill(objRs);
 
for (int i = 0; i < objRs.Rows.Count; i++)
        MessageBox.Show(objRs.Rows[i]["TABLE_NAME"].ToString());