Can't update database with SQL dataAdapter

Posted on 2006-06-06
Last Modified: 2010-04-23
Being new to database programming, I am trying my hand at using code (as opposed to dragging the graphical componants to the form).

I have a simple database on SQL server 2005 express, connected to a Windows form. When trying to update changes I make to to the fields on the form using the sqldataAdapter update command the changes are not committed to the databse.
I use the following line of code to perform the update:


The connection, dataAdapter and dataset were created using the following code:
        Dim sConnectionString As String = _
             "data source=TONI\SQLEXPRESS;" & "initial catalog=Murach;integrated security=SSPI;" & _
             "persist security info=false;workstation id=TONI;packet size=4096"
        Dim cnn As New SqlConnection(sConnectionString)
     The Select statement
    Dim sCustomersSelect = "Select * from Customers"
    Dim DataAdapterCustomers As New SqlDataAdapter(sCustomersSelect, cnn)
       Dim DataSetCustomers As New DataSet()  
I think I need to configure my dataAdapter, but I have no idea how to do that in code. Please help.
Question by:tariqanis2001
    LVL 34

    Accepted Solution

    Provided your table has a primary key this should work, placed somewhere after you have given your dataadapter its Select statement.

       Dim cb As New SQLCommandBuilder(DataAdapterCustomers)

    That will automatically configure the dataadapter with Update, Insert and Delete commands.  You can then just use the DataAdapterCustomers.Update method to get local changes back to the database.



    Author Comment

    Thank you

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    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…

    728 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

    22 Experts available now in Live!

    Get 1:1 Help Now