我可以定义一个包含2个数据源的网格,这些数据源引用2个不同数据库的2条SQL语句吗?

时间:2019-01-10 02:56:02

标签: asp.net vb.net

我有以下Visual Basic代码,这些代码构建了要在ASPX页面内显示的网格:

Imports DevExpress.Data
Imports System.Data
Imports System.Data.SqlClient
Imports DevExpress.Web.ASPxGridView
Imports DevExpress.Web.ASPxEditors

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim MyConnection As SqlConnection
        Dim MyDataAdapter As SqlDataAdapter
        Dim i, j, k As Integer
        Dim DSMe  As Data.DataSet


        Session("ConnectionString") = "Data Source=****SQL;Initial Catalog=*****;User ID=*****;Password=*****"

        MyConnection = New SqlConnection(Session("ConnectionString"))
        MyDataAdapter = New SqlDataAdapter("Getinfo", MyConnection)
        'command type as SP
        MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

        DSMe = New DataSet() 'Create a new DataSet to hold the records
        MyDataAdapter.Fill(DS7, "Getinfo") 'Fill the DataSet with the rows.

        grid1.DataSource = DSMe.Tables(0)
        grid2.DataSource = DSMe.Tables(1)
        grid3.DataSource = DSMe.Tables(2)
        grid4.DataSource = DSMe.Tables(3)
        grid1.DataBind()
        grid2.DataBind()
        grid3.DataBind()
        grid4.DataBind()

现在,我需要修改grid4.DataSource,如下所示:-

grid4.DataSource = DSMe.Tables(4)

所以主要的grid4.DateSource应该同时包含DSMe.Tables(3)DSMe.Tables(4),所以这可能吗?请记住,DSMe.Tables(3)DSMe.Tables(4)是同一存储过程中的sql语句,但是它们引用的是不同的数据库。

0 个答案:

没有答案