日期:2014-05-18 浏览次数:20795 次
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