D
DC
Compiler Error Message: BC30311: Value of type
'System.Web.UI.WebControls.TableCell' cannot be converted to 'Integer'.
on line 63. while trying to write updates using a DataGrids Update method.
Source Error:
Line 61:
Line 62: 'Read in the values of the updated row
Line 63: Dim ID as Integer = e.Item.Cells(0)
Line 64: Dim strTitle as String =
CType(e.Item.Cells(1).Controls(0), TextBox).Text
Line 65: Dim strForeName as String =
CType(e.Item.Cells(2).Controls(0), TextBox).Text
But If I use CType or CInt to convert the TableCell, I get the error...
BC30311: Value of type 'System.Web.UI.WebControls.TableCell' cannot be
converted to 'Integer'. for the line
Dim ID as Integer = CInt(e.Item.Cells(0))
I think I may have a basic conceptual problem with what is happening
here. How does one get a cell from a DataTable in edit mode into an
integer variable?
Here is the code.
Sub dgStaff_Update(sender As Object, e As DataGridCommandEventArgs)
'Read in the values of the updated row
Dim intID as Integer = e.Item.Cells(0)
Dim strTitle as String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim strForeName as String = CType(e.Item.Cells(2).Controls(0),
TextBox).Text
Dim strSurName as String = CType(e.Item.Cells(3).Controls(0),
TextBox).Text
Dim strRoomNo as String = CType(e.Item.Cells(4).Controls(0),
TextBox).Text
Dim strPhoneNo as String = CType(e.Item.Cells(5).Controls(0),
TextBox).Text
Dim strEmail as String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
Dim strStaff as String = CType(e.Item.Cells(7).Controls(0),
TextBox).Text
Dim strRole as String = CType(e.Item.Cells(8).Controls(0), TextBox).Text
'Construct the SQL statement using Parameters
Dim strSQL as String = _
"UPDATE [user_table] SET [Title] = @Title, " & _
"[ForeName] = @ForeName, [SurName] = @SurName " & _
"[RoomNo] = @RoomNo, [PhoneNo] = @PhoneNo " & _
"(e-mail address removed)
'System.Web.UI.WebControls.TableCell' cannot be converted to 'Integer'.
on line 63. while trying to write updates using a DataGrids Update method.
Source Error:
Line 61:
Line 62: 'Read in the values of the updated row
Line 63: Dim ID as Integer = e.Item.Cells(0)
Line 64: Dim strTitle as String =
CType(e.Item.Cells(1).Controls(0), TextBox).Text
Line 65: Dim strForeName as String =
CType(e.Item.Cells(2).Controls(0), TextBox).Text
But If I use CType or CInt to convert the TableCell, I get the error...
BC30311: Value of type 'System.Web.UI.WebControls.TableCell' cannot be
converted to 'Integer'. for the line
Dim ID as Integer = CInt(e.Item.Cells(0))
I think I may have a basic conceptual problem with what is happening
here. How does one get a cell from a DataTable in edit mode into an
integer variable?
Here is the code.
Sub dgStaff_Update(sender As Object, e As DataGridCommandEventArgs)
'Read in the values of the updated row
Dim intID as Integer = e.Item.Cells(0)
Dim strTitle as String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim strForeName as String = CType(e.Item.Cells(2).Controls(0),
TextBox).Text
Dim strSurName as String = CType(e.Item.Cells(3).Controls(0),
TextBox).Text
Dim strRoomNo as String = CType(e.Item.Cells(4).Controls(0),
TextBox).Text
Dim strPhoneNo as String = CType(e.Item.Cells(5).Controls(0),
TextBox).Text
Dim strEmail as String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
Dim strStaff as String = CType(e.Item.Cells(7).Controls(0),
TextBox).Text
Dim strRole as String = CType(e.Item.Cells(8).Controls(0), TextBox).Text
'Construct the SQL statement using Parameters
Dim strSQL as String = _
"UPDATE [user_table] SET [Title] = @Title, " & _
"[ForeName] = @ForeName, [SurName] = @SurName " & _
"[RoomNo] = @RoomNo, [PhoneNo] = @PhoneNo " & _
"(e-mail address removed)