'Error when pressing button in Add User Information listing application
Error (input string was not in a correct format) when button is pressed in Add User Information listing application
int Guestid = Convert.ToInt32((sender as LinkButton).CommandArgument);
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter("GuestViewByID]", sqlcon);
It's not working as you can see in the picture.
Solution 1:[1]
Well, you don't check, show to us what the value of CommandArgument was.
Worse yet, you posted a screen shot in which you could have placed your cursor over the value in the debugger.
So, you need to deal with the fact that CommandArugment might pass a empty string (""), and thus your int conversion will fail.
As a result, try this, and if CommandArugment = "", then you get 0.
int Guestid;
int.TryParse((sender as LinkButton).CommandArgument, out Guestid);
However, while this will fix the error, it DOES NOT fix your logic, since your logic assumes that you supposed to get a value number (int), and you are not.
So, you REALLY need to determine why your commandArgument is not being set to a number, or why it is failing.
So, the above code will fix the error, but not your program logic.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Albert D. Kallal |
