2011-02-23 43 views
0
Line 51: cmd.Parameters.Add("@bprc", SqlDbType.Int).Value = Convert.ToInt32(TextBox4.Text); 
Line 52: cmd.Parameters.Add("@bcat", SqlDbType.VarChar, 50).Value = DropDownList1.SelectedValue; 
Line 53: cmd.Parameters.Add("@bimg", SqlDbType.VarChar, 50).Value = fn; 
Line 54: cmd.Parameters.Add("@bdsc", SqlDbType.VarChar, 500).Value = TextBox6.Text; 
Line 55: cmd.ExecuteNonQuery(); 
+1

你能解釋你的問題嗎? – Adeel 2011-02-23 06:55:47

+0

宣佈'fn'在哪裏?你可以發佈該代碼嗎? – decyclone 2011-02-23 06:58:50

回答

2

看來,您已聲明變量fn但未初始化它。調試,無論你真的將值設置爲fn,這將有所幫助。

1

如果您聲明瞭一個變量,但不會將其分配給任何內容,則會發生這種情況。例如,如果你有以下:

int myInt; 
return Math.Min(0, myInt); 

那麼編譯器會爲您嘗試使用myInt報告錯誤第二行,但是你沒有給它的值。

注意,你會得到即使沒有被設置在myInt只有1 潛在路徑導致此錯誤,例如:

bool myBool = true; 
int myInt; 
if (myBool) 
{ 
    myInt = 1; 
} 
return Math.Min(0, myInt); 

的解決方案是在之前的一些點初始化fn一些合理的價值第53行,或確保它爲所有可能的代碼路徑設置了一些值:

string fn = null; // (assuming `fn` is a string)