Link to home
Start Free TrialLog in
Avatar of johnywhite
johnywhite

asked on

Update Dataset row by name

I have a simple dataset like this:
        Dim stochtable As New Data.DataTable
        stochtable.Clear()
        stochtable.Columns.Add("Symbol")
        stochtable.Columns.Add("Price")
        Me.StochDataSet.Tables.Add(stochtable)

How can I update a row in the datatable by using the symbol name instead of the row number?
Avatar of RonaldBiemans
RonaldBiemans

?????, Do rows have names, I think not. Or maybe I don't understand the question.
aha, I think I do understand :-)

there are several options.

1. if the column Sysmbol is the primary key you can just do

        Dim dr As DataRow = stochtable.Rows.Find("yoursymbol")
        dr.Item("Price") = 10

2. if not you can use a dataview like

        Dim dv As DataView = stochtable.DefaultView
        dv.Sort = "Symbol"
        Dim dr As DataRow = stochtable.Rows(dv.Find("yoursymbol"))
        dr.Item("Price") = 10
Avatar of johnywhite

ASKER

When I try that I get an error "Table does not have a primary key".  I added a primary key to the database and I still get the error.  I am trying to search it by symbol.
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks that worked