I encountered a problem where when the user select the id from the data grid view and click the ‘delete’ button, A error prompts us like this: “Input string was not in the correct format”.
Here are the codes to make you guys have better understanding of the codes.
private void btnDel_Click(object sender, EventArgs e)
{
using (satsEntities Setupctx = new satsEntities())
{
int ID = Int32.Parse(lblID.Text);
var DeleteSL = (from delLS in Setupctx.locationstations
where delLS.locationstationID == ID
select delLS).Single();
Setupctx.DeleteObject(DeleteSL);
Setupctx.SaveChanges();
this.Delete_LS_Load(null, EventArgs.Empty);
MessageBox.Show("Selected Location Station Has Been Deleted.");
}
}
You are getting this exception “Input string was not in a correct format.” on
Your
lblID.Textholds some thing which can’t be converted to a number. May be something that contains characters along with numbers.Try using int.TryParse to see if you can convert the text to number.