G
Guest
Hi can someone please tell me why I keep getting the following error when I execute this code!
I have checked the database and it seems like everything is set as integer for pageID!
Error: Input string was not in a correct format.
<CODE>
Sub DGPages_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
'Read in the values of the updated row
Dim pageID As Integer = e.Item.Cells(1).Text 'Error
Dim modificationDate As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim description As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim title As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
'Construct the Database Connection
Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("PageUpdate", Myconn)
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
' Add Parameters to the SQL query
Dim objID, objModDate, objDescription, objTitle As SqlParameter
objID = cmd.Parameters.Add("@ID", SqlDbType.Int)
objModDate = cmd.Parameters.Add("@ModDate", SqlDbType.DateTime)
objDescription = cmd.Parameters.Add("@Description", SqlDbType.NVarChar)
objTitle = cmd.Parameters.Add("@Title", SqlDbType.NVarChar)
objID.Direction = ParameterDirection.Input
objModDate.Direction = ParameterDirection.Input
objDescription.Direction = ParameterDirection.Input
objTitle.Direction = ParameterDirection.Input
objID.Value = pageID
objModDate.Value = modificationDate
objDescription.Value = description
objTitle.Value = title
Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()
myReader.Close()
Myconn.Close()
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
DGPages.EditItemIndex = -1
BindData()
End Sub
</CODE>
I have checked the database and it seems like everything is set as integer for pageID!
Error: Input string was not in a correct format.
<CODE>
Sub DGPages_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
'Read in the values of the updated row
Dim pageID As Integer = e.Item.Cells(1).Text 'Error
Dim modificationDate As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim description As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim title As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
'Construct the Database Connection
Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("PageUpdate", Myconn)
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
' Add Parameters to the SQL query
Dim objID, objModDate, objDescription, objTitle As SqlParameter
objID = cmd.Parameters.Add("@ID", SqlDbType.Int)
objModDate = cmd.Parameters.Add("@ModDate", SqlDbType.DateTime)
objDescription = cmd.Parameters.Add("@Description", SqlDbType.NVarChar)
objTitle = cmd.Parameters.Add("@Title", SqlDbType.NVarChar)
objID.Direction = ParameterDirection.Input
objModDate.Direction = ParameterDirection.Input
objDescription.Direction = ParameterDirection.Input
objTitle.Direction = ParameterDirection.Input
objID.Value = pageID
objModDate.Value = modificationDate
objDescription.Value = description
objTitle.Value = title
Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()
myReader.Close()
Myconn.Close()
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
DGPages.EditItemIndex = -1
BindData()
End Sub
</CODE>