到INT32我有下面的代碼做一些很簡單的驗證一個TextBox不能轉換零從文本框
if(txtInStock.Text.Length == 0)
txtInStock.Text = Convert.ToString(0);
if (txtInStock.Text.Length == 0)
txtOnOrder.Text = Convert.ToString(0);
int inStockAmt = Convert.ToInt32(txtInStock.Text);
int onOrderAmt = Convert.ToInt32(txtOnOrder.Text);
能正常工作時發短信!= 0,但在文字== 0,我收到了FormatException說該字符串的格式不正確。我該如何解決這個問題?
順便說一句,不需要兩個條件,因爲他們正在檢查相同的條件。 – 2010-02-26 18:17:33