Input string was not in a correct format

  • Thread starter Thread starter Looch
  • Start date Start date
L

Looch

Hi All,

I'm using the following code:

private void cmdConsumUpdate_Click(object sender, EventArgs e)
{
try
{
DataGridViewRow dgvr = dgView2.CurrentRow;
string stat = dgvr.Cells[2].ToString ();
string trac = dgvr.Cells[6].ToString ();
Int32 ticknum =
Convert.ToInt32(dgvr.Cells[8].ToString());
amslpsvr1.WebService ws = new
CustomerService_BreaCS.amslpsvr1.WebService();
ws.UpdateConsumOrder(stat, trac, ticknum);
getInfo();
}
catch (Exception ex)
{
MessageBox.Show (ex.Message)
}
}

I keep getting the error "Input string was not in a correct format.".
I commented out the web service call and got the same error so I know
that's not the issue. I have a feeling this is above the code I have
here but I really don't have any idea what is going on!

Any help would be much appreciated.
 
I believe that is the problem "Int32 ticknum =
Convert.ToInt32(dgvr.Cells[8].ToString())" Are you sure all the cells[8]
are in numbers?
 
Looch,

It is most likely this call:

Int32 ticknum = Covert.ToInt32(dgvr.Cells[8].ToString());

What is the value in dgvr.Cells[8]? Also, why are you calling Convert?
If the type in the cell is an integer, then cast it out, don't convert it to
a string and then convert it back to an int.
 
Nick,

Thanks for the reply.

The cell is a string. If I try "Int32 ticknum =
Covert.ToInt32(dgvr.Cells[8]);" I get 'Cannot convert
system.datagridcell to type Int' (something to that effect) before it
will run in the debugger.
 
You probably are not getting the value of the cell. Try doing something like:

Int32 ticknum =
Covert.ToInt32(dgvr.Cells[8].Value);
 
Back
Top