数据库加入 - 结果显示的GridView [英] Database join - results shown in gridview

查看:88
本文介绍了数据库加入 - 结果显示的GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要的加入,显示结果的ASP三个不同的服务器上三个数据库:GridView控件。我有查询作为ASP的结果,现在的工作:使用连接字符串到一个数据库的SqlDataSource,但我的问题是,我指定服务器,数据库和表对其它两个数据库


  1. 如何修改我的查询使用一个连接字符串的所有
    数据库(C#,ASP的例子)?

  2. 请我做我的查询中的aspx文件或者我应该做的查询,在CS文件?

  3. 如何附上我的结果,如果我做了在CS文件中加入了gridview的?一旦我离开这个页面回来的数据可能会有所不同。

我现在的< ASP:SqlDataSource的> code是这样的 -

 < ASP:SqlDataSource的ID =SqlDataSource1=服务器
的ConnectionString =下;%$的ConnectionStrings:的ConnectionString%>中
的SelectCommand =SELECT DISTINCT A.batchname AS IndexBatchNumber,a.clientkey,a.packagetrackingid,a.statusflag,f.Name AS客户端,选择GroupValue FROM FSDev.dbo.ClientGroup WHERE ClientKey = a.clientkey和组code = TIME ZONE')AS时区,(选择fc.special_instr FROM SQL2.sysdba.FC_SLX_TEST.FC_PKG_TRKG FC WHERE
fc.fc_Pkg_trkgid = a.PackageTrackingID)AS RushFunding FROM BatchExport一个,InvoiceExport B,FSDev.dbo.Clients f其中a.batchname = b.batchname与a.clientkey = f.ClientKey与a.statusflag = 1>&下; / ASP:SqlDataSource的>


解决方案

我已经能够做两件事情来解决这个问题。由于数据库是所有MSSQL,我使用的链接功能加入他们在一起。这样,我只需要有一个连接字符串。为了不具备移动到生产服务器时更改SQL code,我有DBA创建存储过程对所有我的查询。这样,我只需要改变连接字符串。

I have three databases on three different servers that I need to join and show the result in a asp:gridview. I have the query working now as the result of asp:SqlDataSource using the connection string to one database, but my problem is that I specify the server, database and table for the other two databases.

  1. How do modify my query to use a connection string to all of the databases (C#, asp example)?
  2. Do I do my query in the aspx file or should I do the query in the cs file?
  3. How do I attach my result to the gridview if I do the join in the cs file? The data could be different once I leave this page and come back.

My current <asp:SqlDataSource> code is this -

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
SelectCommand="SELECT DISTINCT A.batchname AS IndexBatchNumber, a.clientkey, a.packagetrackingid, a.statusflag, f.Name AS Client, SELECT GroupValue FROM FSDev.dbo.ClientGroup WHERE ClientKey = a.clientkey AND GroupCode = 'TIME ZONE') AS Timezone, (SELECT fc.special_instr FROM SQL2.sysdba.FC_SLX_TEST.FC_PKG_TRKG fc WHERE
fc.fc_Pkg_trkgid = a.PackageTrackingID) AS RushFunding FROM BatchExport a, InvoiceExport b, FSDev.dbo.Clients f WHERE a.batchname = b.batchname AND a.clientkey = f.ClientKey AND a.statusflag = 1 "></asp:SqlDataSource>

解决方案

I have been able to solve this by doing two things. Since the databases are all MSsql, I used the link capabilities to join them together. That way I only have to have a single connection string. In order not to have to change the SQL code when moving to production servers, I had the DBA create stored procedures for all of my queries. This way I only have to change the connection strings.

这篇关于数据库加入 - 结果显示的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆