如何实现像sql2000查询工具的那种查询结果多表显示
如题
一个DataGrid 或者DataGridView 里显示多个不同的表!
[解决办法]
一个dataGridView的数据源对于ds中的一个表
[解决办法]
多个DataGrid或者DataGridView
[解决办法]
private void button1_Click(object sender, EventArgs e) { using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection()) { conn.ConnectionString = "server=ip;uid=sa;pwd=***;database=master"; conn.Open(); using (System.Data.SqlClient.SqlCommand command = conn.CreateCommand()) { command.CommandText = @" select * from sysobjects select getdate() select newid()"; using (System.Data.SqlClient.SqlDataAdapter adp = new System.Data.SqlClient.SqlDataAdapter(command)) { System.Data.DataSet ds = new DataSet(); adp.Fill(ds); foreach (System.Data.DataTable dt in ds.Tables) { System.Windows.Forms.DataGridView dv = new DataGridView(); dv.Dock = DockStyle.Top; dv.Parent = this.panel1; dv.Height = this.panel1.Height / ds.Tables.Count; dv.DataSource = dt; } } } } }
[解决办法]
foreach