CS0161: “UpdatingDBDirectly.GetSelectedRecord()”: 并非所有的代码路径都返回值

sir0721 2008-02-27 09:28:00
下面是问题所在相关代码,请各位大侠帮分析分析!
protected void btnEdit_Click( object sender, EventArgs e)
{
int shipperID = GetSelectedRecord();
string cmd = @"Update Shippers set CompanyName = '" +
this.txtName.Text +
"', Phone ='" + this.txtPhone.Text + "' where ShipperID = " + shipperID;
UpdateDB(cmd);
PopulateGrid();

}
protected int GetSelectedRecord()
{
int shipperID = -1;
int index = GridView1.SelectedIndex;
if (index != -1)
{
DataKey key = GridView1.DataKeys[index];
shipperID = (int)key.Value;
return shipperID;
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
string cmd = @"delete from Shippers where ShipperID =" + GetSelectedRecord();

UpdateDB(cmd);
PopulateGrid();
}
...全文
77 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sir0721 2008-02-27
  • 打赏
  • 举报
回复
问题确实如此,谢谢二位!
Soloboy1020 2008-02-27
  • 打赏
  • 举报
回复
GetSelectedRecord() 函数里面那个if判断如果是假的话就没返回值了 ,所以报错
可以参考1楼的代码改一下
userwjg 2008-02-27
  • 打赏
  • 举报
回复
protected int GetSelectedRecord()
{
int shipperID = -1;
int index = GridView1.SelectedIndex;
if (index != -1)
{
DataKey key = GridView1.DataKeys[index];
shipperID = (int)key.Value;

}
return shipperID;
}
改这样

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧