Professional Web Applications Themes

System.InvalidCastException: Specified cast is not valid. error when updating datagrid - ASP.NET Data Grid Control

Hello, I am trying to update a record using a data grid. I Have a footer column in my data grid that allows users to add a new record. However, I am unable to update any record. I am getting the following error: Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Line 187: Line 188: SKU = dgrd.DataKeys(e.Item.ItemIndex) Line 189: intQtySold = CType(e.Item.Cells(3).Controls(0), TextBox).Text Line 190: decUnitPrice = CType(e.Item.Cells(5).Controls(0), TextBox).Text Line 191: 'creating a connection Stack Trace: [InvalidCastException: Specified cast is not valid.] hw8.dgrd_UpdateCommand(Object s, DataGridCommandEventArgs e) in k:\inetpub\class\~mf14deshmukh\HW\hw8.aspx.vb:189 System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs e) +109 ...

  1. #1

    Default System.InvalidCastException: Specified cast is not valid. error when updating datagrid

    Hello,
    I am trying to update a record using a data grid. I Have a footer
    column in my data grid that allows users to add a new record. However,
    I am unable to update any record.
    I am getting the following error:

    Specified cast is not valid.
    Exception Details: System.InvalidCastException: Specified cast is not
    valid.

    Source Error:


    Line 187:
    Line 188: SKU = dgrd.DataKeys(e.Item.ItemIndex)
    Line 189: intQtySold = CType(e.Item.Cells(3).Controls(0),
    TextBox).Text
    Line 190: decUnitPrice = CType(e.Item.Cells(5).Controls(0),
    TextBox).Text
    Line 191: 'creating a connection


    Stack Trace:


    [InvalidCastException: Specified cast is not valid.]
    hw8.dgrd_UpdateCommand(Object s, DataGridCommandEventArgs e) in
    k:\inetpub\class\~mf14deshmukh\HW\hw8.aspx.vb:189
    System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs
    e) +109
    System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source,
    EventArgs e) +507
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    args) +26
    System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
    EventArgs e) +100
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    args) +26
    System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e) +121
    System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
    eventArgument) +115
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    sourceControl, String eventArgument) +18
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
    +33
    System.Web.UI.Page.ProcessRequestMain() +1277
    PJ Guest

  2. #2

    Default Re: System.InvalidCastException: Specified cast is not valid. error when updating datagrid

    Controls(1)



    "PJ" <poojadeshmukhhotmail.com> wrote in message
    news:5d6e71f9.0404140955.4a6d24d7posting.google.c om...
    > Hello,
    > I am trying to update a record using a data grid. I Have a footer
    > column in my data grid that allows users to add a new record. However,
    > I am unable to update any record.
    > I am getting the following error:
    >
    > Specified cast is not valid.
    > Exception Details: System.InvalidCastException: Specified cast is not
    > valid.
    >
    > Source Error:
    >
    >
    > Line 187:
    > Line 188: SKU = dgrd.DataKeys(e.Item.ItemIndex)
    > Line 189: intQtySold = CType(e.Item.Cells(3).Controls(0),
    > TextBox).Text
    > Line 190: decUnitPrice = CType(e.Item.Cells(5).Controls(0),
    > TextBox).Text
    > Line 191: 'creating a connection
    >
    >
    > Stack Trace:
    >
    >
    > [InvalidCastException: Specified cast is not valid.]
    > hw8.dgrd_UpdateCommand(Object s, DataGridCommandEventArgs e) in
    > k:\inetpub\class\~mf14deshmukh\HW\hw8.aspx.vb:189
    >
    System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs
    > e) +109
    > System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source,
    > EventArgs e) +507
    > System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    > args) +26
    > System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
    > EventArgs e) +100
    > System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    > args) +26
    > System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e) +121
    >
    System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
    stBackEvent(String
    > eventArgument) +115
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    > sourceControl, String eventArgument) +18
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
    > +33
    > System.Web.UI.Page.ProcessRequestMain() +1277

    Michael Tkachev Guest

Similar Threads

  1. System.InvalidCastException was unhandled
    By Paul_Heinisch@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 1
    Last Post: October 3rd, 09:32 PM
  2. dataGrid_ItemDataBound - System.InvalidCastException
    By AZNewsh in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: November 18th, 05:31 PM
  3. Replies: 1
    Last Post: August 6th, 03:26 AM
  4. Cast from type 'DBNull' to type 'String' is not valid error
    By Rob in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: July 28th, 09:11 PM
  5. Replies: 3
    Last Post: July 10th, 10:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139