New Row in DataTable - problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Agnes

    #1

    New Row in DataTable - problem

    I use Execute Reader to get a list of data and want to add to the datatable.
    I got an error in the 1st row. "Specified arguement was out of the range of
    valid values. Parameter name :rowindeX"
    my code is listed as following :Please be kind to help me take a look. I
    really don't know what's wrong it is.

    Dim drRv As SqlDataReader
    Dim myDatarow As DataRow
    drRv = cmdRv.ExecuteRe ader

    While drRv.Read
    myDatarow = Me.dtInvCharges .NewRow()
    MessageBox.Show (drRv.Item("bas eamt")) <--- It can show the
    correct value
    intCounter += 1
    With myDatarow
    .Item("acctcode ") = drRv.item("acct code") <--- It got
    that errors.
    End With

    Me.dtInvCharges .Rows.Add(myDat arow)
    end while


  • Marina

    #2
    Re: New Row in DataTable - problem

    It looks like there is no column called 'acctcode' in the result set.

    "Agnes" <agnes@dynamict ech.com.hk> wrote in message
    news:uRHCVp$pFH A.3180@TK2MSFTN GP15.phx.gbl...[color=blue]
    >I use Execute Reader to get a list of data and want to add to the
    >datatable.
    > I got an error in the 1st row. "Specified arguement was out of the range
    > of valid values. Parameter name :rowindeX"
    > my code is listed as following :Please be kind to help me take a look. I
    > really don't know what's wrong it is.
    >
    > Dim drRv As SqlDataReader
    > Dim myDatarow As DataRow
    > drRv = cmdRv.ExecuteRe ader
    >
    > While drRv.Read
    > myDatarow = Me.dtInvCharges .NewRow()
    > MessageBox.Show (drRv.Item("bas eamt")) <--- It can show the
    > correct value
    > intCounter += 1
    > With myDatarow
    > .Item("acctcode ") = drRv.item("acct code") <--- It got
    > that errors.
    > End With
    >
    > Me.dtInvCharges .Rows.Add(myDat arow)
    > end while
    >[/color]


    Comment

    • Agnes

      #3
      Re: New Row in DataTable - problem

      I solve my bugs,Since my datagrid is bind to the table,
      (1)Me.dgCharges .Readonly = false
      (2)Me.dgCharges .Enabled = True
      (3) change " dim myDatarow as datarow =Me.dtInvCharge s.NewRow() "

      "Marina" <someone@nospam .com> ¼¶¼g©ó¶l¥ó·s»D: eUf0eaAqFHA.366 4@TK2MSFTNGP10. phx.gbl...[color=blue]
      > It looks like there is no column called 'acctcode' in the result set.
      >
      > "Agnes" <agnes@dynamict ech.com.hk> wrote in message
      > news:uRHCVp$pFH A.3180@TK2MSFTN GP15.phx.gbl...[color=green]
      >>I use Execute Reader to get a list of data and want to add to the
      >>datatable.
      >> I got an error in the 1st row. "Specified arguement was out of the range
      >> of valid values. Parameter name :rowindeX"
      >> my code is listed as following :Please be kind to help me take a look. I
      >> really don't know what's wrong it is.
      >>
      >> Dim drRv As SqlDataReader
      >> Dim myDatarow As DataRow
      >> drRv = cmdRv.ExecuteRe ader
      >>
      >> While drRv.Read
      >> myDatarow = Me.dtInvCharges .NewRow()
      >> MessageBox.Show (drRv.Item("bas eamt")) <--- It can show the
      >> correct value
      >> intCounter += 1
      >> With myDatarow
      >> .Item("acctcode ") = drRv.item("acct code") <--- It got
      >> that errors.
      >> End With
      >>
      >> Me.dtInvCharges .Rows.Add(myDat arow)
      >> end while
      >>[/color]
      >
      >[/color]


      Comment

      Working...