General information
Title:
Problem with updating a datagrid in vb.net
I'm new to the vb.net environment. I have created a web form containing a datagrid, sqldataadapter, sqlconnection and dataset. The dataset is boundto a table containing fields in the order of pws_id, violation_id, status, action_date. The datagrid is able to edit,save,cancel,update,and delete any row of data. The problem I'm having is that I cannot perform an update when calling DataGrid1_UpdateCommand() subroutine and cannot figure out why.
Any help would be appreciated.
The error i'm getting is:
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 141: Dim pws_id As String = CType(e.Item.Cells(0).Controls(0), TextBox).Text
Line 142: myrow.pws_id = pws_id
Source File: c:\inetpub\wwwroot\jj\testapp\WebForm2.aspx.vb Line: 141
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
testapp.WebForm2.DataGrid1_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\jj\testapp\WebForm2.aspx.vb:141
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) +109
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +507
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +106
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1277
-----------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
The subroutine created this error is:
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim myrow As DataSet1.vioactionRow
myrow = DataSet11.vioaction.FindBypws_id(e.Item.ItemIndex)
Dim pws_id As String = CType(e.Item.Cells(0).Controls(0),TextBox).Text
myrow.pws_id = pws_id
Dim p_vio_id As Integer = CType(e.Item.Cells(1).Controls(0),TextBox).Text
myrow.violation_id = p_vio_id
Dim p_status As String = CType(e.Item.Cells(2).Controls(0),TextBox).Text
myrow.status = p_status
Dim p_act_date As DateTime = CType(e.Item.Cells(3).Controls(0), TextBox).Text
myrow.action_date = p_act_date
SqlDataAdapter1.Update(DataSet11)
DataGrid1.EditItemIndex = -1
DataBind()
End Sub
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only