getRecords のリストで getRecords2 のリストを追加しようとしています。getRecords でなぜか処理に時間がかかり、呼び出すとタイムアウトしてしまいます。
public static List<ListA> getRecords2(string id)
{
List<ListA> listOfRecords = new List<ListA>();
using (SqlConnection con = SqlConnect.GetDBConnection())
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "sp2";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@id", id));
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
ListA listMember = new ListA();
listMember.ID = (int)reader["ID"];
listMember.Name = reader["FullName"].ToString().Trim();
}
con.Close();
}
return listOfRecords;
}
public static List<ListA> getRecords(string id)
{
List<ListA> listOfRecords = new List<ListA>();
using (SqlConnection con = SqlConnect.GetDBConnection())
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "sp1";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@id", id));
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
ListA listMember = new ListA();
listMember.ID = (int)reader["ID"];
listMember.Name = reader["FullName"].ToString().Trim();
}
con.Close();
}
List<ListA> newlist = getRecords(id);
foreach (ListA x in newlist) listOfRecords.Add(x);
return listOfRecords;
}
getRecords2 に getRecords のリストを追加します。私はそれを間違っていますか?