我在頁面C#ASP.NET傳遞,如果else語句字符串值到另一個字符串
public partial class Reports : System.Web.UI.Page
{
private string myquery = null;
MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
usertype = Session["usertype"].ToString();
{
if (usertype == "admin")
{
string myquery = @"SELECT jobId, odometerReading, jobDescription, status FROM joborder Where truck_id = '" + truck_id + "'";
}
else
{
string myquery = @"SELECT jobId, odometerReading, jobDescription, status FROM joborder Where truck_id = '" + truck_id + "' and status = '1'";
}
}
connectDB();
}
}
有這樣的代碼我如何我myquery
字符串值設置爲我的if else語句在我的頁面加載類?我現在的代碼總是設置爲myquery
至null
。
您在if條件申報 「更改爲MyQuery」 再次讀取數據,去除串關鍵字如果CAND else條件,然後再試一次。 –