想要通过asp.net设计一个页面,可以显示出在不同服务器上数据库的某个表的所有数据(表结构相同)。

2020-07-27 科技 150阅读
你复制代码,修改数据库连接,以及sqlcommand,就可以实现

Dim ds As DataSet = New DataSet()
Dim conn As SqlConnection = New SqlConnection("server=FZ545X1\SQLEXPRESS;integrated security=true;database=demo")
Dim da As SqlDataAdapter = New SqlDataAdapter()
Dim cmd As SqlCommand = New SqlCommand("select * from dbo.class", conn)
conn.Open()
da.SelectCommand = cmd
da.Fill(ds, "table")
conn.Close()
Dim conn2 As SqlConnection = New SqlConnection("server=FZ545X1\SQLEXPRESS;integrated security=true;database=demo2")
Dim da2 As SqlDataAdapter = New SqlDataAdapter()
Dim cmd2 As SqlCommand = New SqlCommand("select * from dbo.class", conn)
conn2.Open()
da2.SelectCommand = cmd
da2.Fill(ds, "table")
conn2.Close()
Me.GridView1.DataSource = ds
Me.GridView1.DataBind()
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com