私は単純なC#アプリケーション(Azure SQLデータベースを使用しています)で作業しています。最初に私のアプリは名前を保存し、次にすべての人を表示することで、データベースからすべての保存された名前を取得するはずです。何らかの理由で私のコードがデータベースから名前を取得できないので、すべての人を表示すると反応しません。それを修正する手助けができますか?私の残りのコントローラクラスから(C#)Azure SQLデータベースからデータを取得する際の問題
:
public List<Person> getPersons()
{
List<Person> persons = new List<Person>();
String sql = "SELECT * from users";
try
{
SqlCommand command = new SqlCommand(sql, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
persons.Add(new Person(reader.GetInt32(0), reader.GetString(1)));
}
}
catch(Exception e)
{
System.Diagnostics.Debug.WriteLine("Error in getPersons(): " + e.Message);
}
return persons;
}
すべての人を表示するコードをデバッグしましたか?何かエラーがありますか? 'getPersons'メソッドのコードがうまく動作するかどうか確認しましたか? –