“ if (period.Tostring() = "1 year") ”的问题想要检查数据库 nvarchar 并执行一个循环,因为我需要对其进行转换,但它给了我一条红线。
string strCommandText4 = "SELECT autoLoanPeriod From AutoLoan WHERE userID= '" + Session["userID"] + "';";
SqlCommand myCommand4 = new SqlCommand(strCommandText4, myConnection);
var period = myCommand.ExecuteScalar();
if (period.ToString() = "1 year")
{
for (int i = 0; i<= 12; i++)
{
string strCommandText5 = "INSERT INTO AutoTrans VALUES(@loanID,@transPeriod,null,@transStatus);";
SqlCommand myCommand5 = new SqlCommand(strCommandText5, myConnection);
myCommand5.Parameters.AddWithValue("@loanID", Session["@loanID"].ToString());
myCommand5.Parameters.AddWithValue("@transPeriod", numPeriod);
myCommand5.Parameters.AddWithValue("@transStatus", status);
}
}