데이터베이스에 두 개의 테이블이 있습니다. 학생과 계정. 내 응용 프로그램에서 reader.GetDecimal() 메서드를 사용하여 여러 테이블에서 데이터를 읽는 데 문제가 있고 두 번째 테이블에서 데이터를 가져 오는 데 문제가 있습니다.reader.GetDecimal()을 별도의 테이블에있는 열에 사용하는 방법은 무엇입니까?
GetDecimal 메서드를 사용하여이 작업을 수행 할 수 있습니까? 또는 계정 테이블에서 필요한 것을 얻으려면 쿼리 중 하나에 추가해야합니까?
데이터베이스 테이블 :
계정
학생
코드 :
//Query Student table for bAlertSetup
SqlCeCommand AlertQuery = new SqlCeCommand("SELECT * from Students AND Accounts", conn);
reader = AlertQuery.ExecuteReader();
while (reader.Read())
{
bSinglePersonAlertSetup = reader.GetBoolean(5);
if (bSinglePersonAlertSetup == true)
{
int AccountID = reader.GetInt32(7);
decimal Threshold = reader.GetDecimal(6);
//decimal Total = get decimal from the accounts table where accountID (in the accounts table) = AlertAccountID
//See if Students account is below the defined threshold
if (Total < Threshold)
{
StudentEmailAddress = reader.GetString(3);
if (StudentEmailAddress != null)
{
Console.WriteLine(StudentEmailAddress);
mail.To.Add(StudentEmailAddress);
//Update bAlertSetup
SqlCeCommand UpdateBool = new SqlCeCommand("UPDATE Students set bSendAlert = 0 WHERE UserId = @ID");
UpdateBool.Parameters.AddWithValue("@ID", reader.GetInt32(0));
UpdateBool.Connection = conn;
UpdateBool.ExecuteNonQuery();
}
}
}
편집 : 여기
내가 필요한 열이 올바르게 두 테이블을 조인 믿고 사용하고있는 새 쿼리입니다. 이제 GetDecimal() 메서드에서 사용할 각 열의 인덱스를 얻으려면 어떻게해야합니까?
SqlCeCommand AlertQuery = new SqlCeCommand("SELECT st.bAlertSetup, st.AccountThreshold, st.AlertAccountID, acc.AccountID, acc.AccountTotal FROM Students st INNER JOIN Accounts acc ON st.AlertAccountID = acc.AccountID", conn);
이 시도 도움이 될 것입니다 사용할 수 있습니다 read.GetDecimal (6)로 .toString()를. – Marek
두 번째 테이블에서 열을 가져 오려면 여기에서 쿼리를 편집해야합니다. – Ehsan
나는 그 부분이 현재 어떻게 올바르게 작동한다고 믿는다. 내가 겪고있는 문제는 계정 테이블에서 해당 "AccountID"및 "AccountTotal"을 얻는 것입니다. –