ashish sadasing

ashish sadasing

  • NA
  • 22
  • 11.4k

Looping through multiple database name (IBM db2)

Jan 21 2016 5:16 AM
Hello everyone,
 
I am a beginner in ASP.NET C#.
I am trying to build a dashboard. The database is IBM db2. I am using asp.net webpages to develop it.
Infact, i have several connection string and i am trying to loop through the database name to open each database.
Code :  
 
//declaration of array of database name found in the web.config 
string[] clients = {"database_name1", "database_name2"};
//database connection
foreach (var client in clients) { 
   var db = Database.Open(client);
//simple query
var selectedClient = db.Query("SELECT * FROM DB2INST1.CUSTOMERS FETCH FIRST 1 ROWS ONLY"); 
}
//display query
@foreach(var row in selectedClient) {
   @row.CUSTOMERNAME
}
Compiler Error Message: CS0103: The name 'selectedClient' does not exist in the current context
------------------
But if i use directly the exact database name without the loop, the same code works.
Example :
var db = Database.Open("database_name1");

I hope you can help me guys...Thank you
 

Answers (2)