Je remplis le jeu de données deux fois,L'ensemble de données contient une seule table
le nom de la table n'a jamais été défini correctement. Je ne vois qu'une seule table dans le DataSet
Qu'est-ce que les chances?
public static DataSet GetSchoolTree()
{
BLLBase.CreateConnection();
BLLBase.Connection.Open();
DataSet dataSet = new DataSet("SS");
Stages.GetStages(ref dataSet);
Schools.GetSchools(ref dataSet);
BLLBase.Connection.Close();
dataSet.Relations.Add(dataSet.Tables["Schools"].Columns["ID"], dataSet.Tables["dbo.Stages"].Columns["School_ID"]);
return dataSet;
}
internal static void GetSchools(ref DataSet dataSet)
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.TableMappings.Add("dbo.Schools", "Schools");
SqlCommand command = new SqlCommand();
command.CommandText = "[dbo].[SR_School_ALL]";
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Connection = BLLBase.Connection;
adapter.SelectCommand = command;
adapter.Fill(dataSet);
}
internal static void GetStages(ref DataSet dataSet)
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.TableMappings.Add("dbo.Stages", "Stages");
SqlCommand command = new SqlCommand();
command.CommandText = "[dbo].[Stp_Stages_All]";
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Connection = BLLBase.Connection;
adapter.SelectCommand = command;
adapter.Fill(dataSet);
}
grâce
Pourriez-vous s'il vous plaît signaler votre code. Il y a peut-être une différence entre votre code et l'exemple. Il pourrait juste y avoir un bug dans l'exemple. De plus, le lien que vous avez posté ne fonctionne pas pour moi. – funkymushroom
dans le débogueur, essayez dataset.tables.count & le lien ne fonctionne pas. – SoftwareGeek