我一直在嘗試檢索貸款額度,並希望它是浮動的。但是,loanAmount返回值爲0.0。 btw的SQL語句只返回一個值。請幫忙?將SQLreader轉換爲浮點型?
SqlCommand cmd5 = new SqlCommand();
cmd4.Connection = conn;
cmd4.CommandText = "SELECT loanAmount FROM LoanPortfolio WHERE custID='" + custIDs + "' AND loanType LIKE 'Personal Loan'";
conn.Open();
float loanAmount = 0.0F;
SqlDataReader amountLoan = cmd4.ExecuteReader();
while (amountLoan.Read())
{
loanAmount = float.Parse(amountLoan.ToString());
break;
}
conn.Close();
可能重複的[無法強制'System.Data.SqlClient.SqlDataReader'類型的對象類型'System.IConvertible'](http://stackoverflow.com/questions/17928388/unable-to-cast-object -of-type-system-data-sqlclient-sqldatareader-to-type-sys) – JLRishe