如何将三个数据库结果存储到单个字符串数组中 [英] How to Store Three Database Result into Single String Array

查看:72
本文介绍了如何将三个数据库结果存储到单个字符串数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我非常困惑将三个查询结果存储到数组中.
我的主要问题是我有一个类似:
的查询

Hello,

i am very confusing to store three query result in to array.
My main problem is that i have a query like :

con2.ConnectionString = @"Data Source=DATA-SERVER;Initial Catalog=" + database_name[k] + ";User ID=xxxxxxxxxx";
           con2.Open();
           DataSet ds1 = new DataSet();
           SqlDataAdapter myda = new SqlDataAdapter("select distinct(refby) from glmast where refby<>'' and inde='d' order by refby", con2);
           myda.Fill(ds1);
           if (ds1.Tables[0].Rows.Count != 0)
           {//
           }


myda是myquery.例如我有三个数据库,它们存储到databse_name数组中,根据该数据库,我想将refby名称存储到数组中.但是如何首先使用值初始化数组以及如何将所有值存储到Array中.

之后,所有进入数组的值都将显示在下拉列表中.我尝试将下拉列表与上述查询绑定,但需要最后一个数据库值.

请帮帮我..
Mitesh


myda is myquery. E.g i have three database which store into databse_name array and according to that database i want to store refby name into array. but how first initialize array with value and how to store all values into Array.

After that all values come into Array is display into Dropdown list.i try to bind dropdown with above query but it takes last database Value.

Please Help Me..
Mitesh

推荐答案

您的意思是您拥有结构相同的三个不同数据库,并且要对它们运行相同的查询并收集结果?
您可以将它们合并到代码中,但是如果所有三个数据库都在同一实例上,则在SQL Server级别更容易做到.根据您的连接字符串就是这种情况.
进行如下操作:使用连接字符串中的任何db-s,并使用StringBuilder和一个循环,创建一个查询,该查询使用数据库名称来合并所有需要的值以完全限定表和字段.
databasename.schema.table,如果需要的话databasename.schema.table.field
由于实例而不是数据库是SQL Servder中的顶级概念,因此您可以简单地引用同一实例的数据库之间的表和视图.您甚至可以在实例或不同服务器之间进行选择,但这在这里不需要.
You mean you have three different databases with the same structure, and you want to run the same query on them and gather the result?
You can combine them in your code, but is more easy to do it on SQL Server level, if all three databases are on the same instance. According to your connection string this is the case.
Proceed like this: use any of the db-s in the connection string, and using a StringBuilder and a cycle, create a query, that unions all needed values using the databases names to fully qualify tables and fields.
databasename.schema.table and if needed databasename.schema.table.field
Since the instance and not the database is the top level concept in SQL Servder, you can simply reference tables and views between databases of the same instance. You even can select between instances or different servers, but that is not needed here.


这篇关于如何将三个数据库结果存储到单个字符串数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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