我在變量FaxPro
,EmailPro
,FaxStat
和EmailStat
上收到錯誤。C#中的故障設置變量
while (reader.Read())
{
string CustNo = reader["CUSTNO"].ToString();
string Phone = reader["PHONE"].ToString();
string Fax = reader["FAX"].ToString();
string Email = reader["PRI_EMAIL"].ToString();
string Type = reader["TYPE"].ToString();
if (Type.Contains("H"))
{
if (Type.Contains("F"))
{
string FaxStat = "Y";
string FaxPro = "PENDING";
}
else
{
string FaxStat = "N";
string FaxPro = "NONE";
}
if (Type.Contains("E"))
{
string EmailStat = "Y";
string EmailPro = "PENDING";
}
else
{
string EmailStat = "N";
string EmailPro = "NONE";
}
//outbox
// id, account, type, title, number, fax, email, faxpro, emailpro, faxstat, emailstat, filepath, datesent
MySqlCommand mycommand = new MySqlCommand("INSERT INTO outbox (id, account, type, title, number, fax, email, faxpro, emailpro, faxstat, emailstat, filepath, datesent) VALUES('0','" + CustNo + "', 'CUSTOMER', 'test', '" + Phone + "', '" + Fax + "', '" + Email + "', '" + FaxPro + "', '" + EmailPro + "', '" + FaxStat + "', '" + EmailStat + "', 'test', NOW())", conn);
mycommand.ExecuteNonQuery();
錯誤是:... \爲Form2.cs
...等等:
'FaxPro' 這個名字不會在目前情況下存在C
EmailPro
,FaxStat
和EmailStat
。
您的變量超出範圍 - 它們只存在於它們被聲明的{大括號}之間。請閱讀[變量作用域](http://msdn.microsoft.com/en-us/library/aa691132%28VS.71%29.aspx) –
您應該小寫變量名稱。 –