Gridview Update Insert Rows - string conversion error

nfgeada

Member
Joined
Mar 30, 2008
Messages
5
Programming Experience
Beginner
Hi,
(i'm developing my project in visual basic with webdeveloper2008)
I have my gridview with a insert(inserir) and update(actualizar) and when i click update it returns me this error: "Conversion from strin to integer is not valid" and this points to this code:

If IsNumeric(CInt(CType(.FindControl("lblID"), Label).Text)) Then
If CInt(CType(.FindControl("lblID"), Label).Text) > 0 Then
id = CInt(CType(.FindControl("lblID"), Label).Text)
End If
End If
iCatID = UpdateMarca(n_inventario, n_imobilizado, tipo, modelo, marca, serial_n, local_inst, ano_imobilizado, data_compra, activo, id)
End With
Next
lblResultados.Text = "Actualização realizada com sucesso."

Help Me pliz!!!

MY BEST REGARDS
 
CType(.FindControl("lblID"), Label).Text

Why do this instead of using a reference to the variable like the following?

lblID.Text

As for the Exception, you do check to make sure it is a number before converting to String, but you also convert it during your check like this : "IsNumeric(CInt(". This actually does a CInt() before it does the IsNumeric() so this is the line giving you the error. Try to remove the CInt in the If's condition. You could also use a Try and catch block to handle the Exception...

http://msdn.microsoft.com/en-us/library/fk6t46tz(VS.71).aspx

Also, it is better practice to avoid the CSomething functions. You can use Integer.Parse() and Integer.TryParse() to do the same.
 

Latest posts

Back
Top