Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

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

C#
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 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
Posted
Updated 29-Jun-12 20:31pm
v3

1 solution

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.
 
Share this answer
 
Comments
AshishChaudha 30-Jun-12 2:56am    
good answer..my 5!
Zoltán Zörgő 30-Jun-12 7:32am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900