我填充數據集兩次,數據集僅保留一個表
表名從未正確設置。 我在數據集中只看到一個表格
什麼是機會?
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);
}
感謝
請問你可以發佈你的代碼。也許你的代碼和例子有區別。這個例子中可能只是一個錯誤。另外,您發佈的鏈接對我無效。 – funkymushroom 2010-08-07 16:00:00
在調試器中,嘗試dataset.tables.count和鏈接不起作用。 – SoftwareGeek 2010-08-07 16:02:20