次のコードは単一の DataSet で動作しますが、DataSet 配列で実行しようとすると SqlDataAdapter.Fill() が動作しません。基本的に私がやろうとしているのは、6 つの異なるデータベースを接続し、それらに対して同じ SQL クエリを実行し、すべてのデータをまとめて収集し、6 つのデータベースからのデータ全体を単一の dataGridView に表示することです。どうやってするの?ありがとう、
DataSet[] mySet = new DataSet[6];
DataSet finSet = new DataSet();
for (int j = 0; j <= 5; j++)
myConnection.Open();
for (int i = 0; i <= specRowCount - 2; i++)
{
cleanDesc = dataGridView2.Rows[removalPointer].Cells[1].Value.ToString().Replace("'", "''").Trim();
classname = dataGridView2.Rows[removalPointer].Cells[0].Value.ToString().Trim();
str = "use " + myDatabases[j] + " SELECT top 1 x, y, z, t, h, f, d, " +
"s, d, c, s, a, d, f, g, " +
"s, f, a, dFROM tttt where c=1 and a=1 and " +
"d='" + cleanDesc + "' and d= '" + d+ "'";
myAdapter = new SqlDataAdapter(str, myConnection);
myAdapter.Fill(mySet[j], "tttt");
if (countRows != mySet[j].Tables["tttt"].Rows.Count)
{
mySb.AppendLine(dataGridView2.Rows[removalPointer].Cells[1].Value.ToString());
dataGridView2.Rows.Remove(dataGridView2.Rows[removalPointer]);
}
else
{
removalPointer++;
}
countRows = mySet[j].Tables["tttt"].Rows.Count;
finSet.Merge(setArray[j]);
dataGridView1.DataSource = finSet.Tables["tttt"];
}
myConnection.Close();
MessageBox.Show("Con closed!");
}