注册 登录
编程论坛 ASP.NET技术论坛

为何出现:使用了未赋值的局部变量“MyText” 的错误???

foshan 发布于 2007-03-15 13:08, 1599 次点击

String MyText;
//添加数据
if (RadioButtonList1.Text.ToString() == "工程报表" && RadioButtonList1.Text.ToString() == "实情汇报")
{ MyText = "工程报表及实情汇报"; }
if (RadioButtonList1.Text.ToString() == "工地检查通知" && RadioButtonList1.Text.ToString() == "工地检查通报")
{ MyText = "工地检查通知及通报"; }
DataRow addrow = ds2.Tables[0].NewRow();
addrow[1] = DropDownList1.Text + "年" + DropDownList2.Text + "月";
addrow[2] = RadioButtonList1.SelectedIndex + 1;
addrow[3] = "files/" + DropDownList1.Text + "年/" + MyText + "/" + FileUpload1.FileName;
ds2.Tables[0].Rows.Add(addrow);
GridView1.DataSource = ds2.Tables["baobiao"]; //显示,绑定
GridView1.DataBind();
//da2.Update(ds2, "baobiao");

-------------------------------------------

“/showbaobiao”应用程序中的服务器错误。
--------------------------------------------------------------------------------

编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。

编译器错误信息: CS0165: 使用了未赋值的局部变量“MyText”

源错误:

行 126: addrow[1] = DropDownList1.Text + "年" + DropDownList2.Text + "月";
行 127: addrow[2] = RadioButtonList1.SelectedIndex + 1;
行 128: addrow[3] = "files/" + DropDownList1.Text + "年/" + MyText + "/" + FileUpload1.FileName;
行 129: ds2.Tables[0].Rows.Add(addrow);
行 130: GridView1.DataSource = ds2.Tables["baobiao"]; //显示,绑定

4 回复
#2
skyland842007-03-16 10:33
String Mytext=null;

你可能是 两个if 都 不 没有通过。也就是说 你的 mytext 没有赋值 不知道指到哪里去了!
#3
foshan2007-03-16 10:49
谢谢!就是这个问题,后来我写成 String Mytext="A";就没事了,但不知道原因所在。谢谢 上楼 朋友解释原因所在。
#4
chenjin1452007-03-16 11:00
String MyText

你只定义了一个String的引用而已

所以出错
#5
foshan2007-03-19 09:33
明白了,谢谢!
1