CS0161: “UpdatingDBDirectly.GetSelectedRecord()”: 并非所有的代码路径都返回值
下面是问题所在相关代码,请各位大侠帮分析分析!
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();
}