Update Dataset row by name

Posted on 2005-04-27
Last Modified: 2010-04-23
I have a simple dataset like this:
        Dim stochtable As New Data.DataTable

How can I update a row in the datatable by using the symbol name instead of the row number?
Question by:johnywhite
    LVL 25

    Expert Comment

    ?????, Do rows have names, I think not. Or maybe I don't understand the question.
    LVL 25

    Expert Comment

    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

    Author Comment

    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.
    LVL 25

    Accepted Solution

    If you made the column symbol the primary key in the database you must also add it to the datatable in your program
    by letting the dataadapter add the key


            da.MissingSchemaAction = MissingSchemaAction.AddWithKey

    or by setting it explicitly in code

    Stochtable.PrimaryKey = New DataColumn() {stochtable("Symbol")}


    Author Comment

    Thanks that worked

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now