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("Sy mbol")
stochtable.Columns.Add("Pr ice")
Me.StochDataSet.Tables.Add (stochtabl e)
How can I update a row in the datatable by using the symbol name instead of the row number?
Dim stochtable As New Data.DataTable
stochtable.Clear()
stochtable.Columns.Add("Sy
stochtable.Columns.Add("Pr
Me.StochDataSet.Tables.Add
How can I update a row in the datatable by using the symbol name instead of the row number?
?????, 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("your symbol")
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("y oursymbol" ))
dr.Item("Price") = 10
there are several options.
1. if the column Sysmbol is the primary key you can just do
Dim dr As DataRow = stochtable.Rows.Find("your
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("y
dr.Item("Price") = 10
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks that worked