Why isn't a dataset updating

Posted on 2006-04-11
Last Modified: 2010-04-23
I'm at a loss and don't even know what code to share to have someone help me.

I have 3 tables: client, spouse, addresses.  I have datasets for each one.  The client record is the primary table and has its primary key in spouse and addresses.  

I can create a client and modify as I wish.

After creating the client, I can add a spouse and modify as needed.

After creating the client, I can add an address with no problem.  Once I try to modify I get the exception, Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

I am at a loss of where to begin to solve this.  For spouse and addresses I have added identical sql queries, where spouse.clientid = and addresses.clientid = (otherwise I would be able to pull the correct data to match the client, which is happening just fine).

Can someone help?  I've spent hours on this and have given us.
Question by:vlvawter
    LVL 62

    Expert Comment

    by:Fernando Soto
    Hi vlvawter;

    Have you added a CommandBuilder object to the DataAdapter? It sounds like you do not have the commands set up in the adapter.

    If not add a line of code line this after you have created the DataAdapter.

    If using SQL classes

        Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)

    If using OleDB classes

        Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)

    Where the da in the above commands are the respective DataAdapters, SqlDataAdapter or OleDbDataAdapter.

    Hope that this is of some help.


    Author Comment


    I have created the dataset with the built-in wizards, which is supposed to set up all the lower level commands for me.  I have created all three tables from the same database.  Two of them work every time (without my having to create a CommandBuilder) and one works intermittantly.  

    I can go the route you're talking about, but I'd rather know first of all if there is a quirk in the auto-dataset routine that I don't know about.  I'm going to wait and see if anyone knows the answer to this.  If not, I'll have to go your route and code on a lower level.  I was wanting to avoid that.  If I have to go that route, I'll award you the points.
    LVL 96

    Accepted Solution

    When you dragged the data adapter to your form, and went through the wizard, did it say that it successfully created all 4 command types (Select, Delete, Insert, and Update)?  In order to use the Select SQL statement to build the other 3 commands, you need to include primary key information.


    Author Comment


    Your comments put me onto the path that finally solved my problem.  I wanted more than a solution; I wanted the reason why I was having problem.  Finally I realized that if I were updating a record, unless I created a sql query that found my record, then I had to have a primary key.  The adapter would not know which record to update otherwise.  Once I added a primary key, deleted and recreated the datasets, everything worked fine.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now