开发者

use of unassigned local variable 'fn'

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", SqlDb开发者_如何学CType.VarChar, 50).Value = fn;
Line 54: cmd.Parameters.Add("@bdsc", SqlDbType.VarChar, 500).Value = TextBox6.Text;
Line 55: cmd.ExecuteNonQuery();


It seems, you have declared variable fn but did not initialize it. Debug, whether you really set any value to fn, this will help.


This happens if you declare a variable, but then don't assign it to anything. For example if you had the following:

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

Then the compiler would report an error second line as you tried to use myInt, but you didn't give it a value.

Note that you will get this error even if only 1 potential path results in myInt not being set, for example:

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

The solution is to initialise fn to some sensible value at some point before line 53, or ensure that it is set to some value for all possible code paths:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜