Solved

update requires a valid updatecommand when passed datarow collection with modified rows

Posted on 2007-11-15
8
7,470 Views
Last Modified: 2012-06-22
Hi.
Im simply use the datasheet wizard for create a dataset with my  sql table for edit, delete update information, but the update buton did not work, taking the error message that have in the question title.

the code is this.
**************************************************
Public Sub UpdateDataSource(ByVal ChangedRows As WindowsApplication1.indice)
        Try
            'Sólo es necesario actualizar el origen de datos si hay cambios pendientes.
            If (Not (ChangedRows) Is Nothing) Then
                'Abra la conexión.
                Me.OleDbConnection1.Open()
                'Intente actualizar el origen de datos.
                'OleDbDataAdapter1.Update(ChangedRows)
                OleDbDataAdapter1.Update(ChangedRows)
                Me.OleDbConnection1.Close()

            End If
        Catch updateException As System.Exception
            'Agregar aquí el código de control de errores.
            Throw updateException
        Finally
            'Cerrar la conexión independientemente de si se inició una excepción o no.
            Me.OleDbConnection1.Close()
        End Try

    End Sub
******************************************
please is anybody help me to fix this error
thank you
edo
0
Comment
Question by:edo60
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 

Author Comment

by:edo60
ID: 20292931
****the error code again*****

Public Sub UpdateDataSource(ByVal ChangedRows As WindowsApplication1.indice)
       

        Try
                        If (Not (ChangedRows) Is Nothing) Then
                               Me.OleDbConnection1.Open()
                                             OleDbDataAdapter1.Update(ChangedRows)
                Me.OleDbConnection1.Close()

            End If
        Catch updateException As System.Exception
                        Throw updateException
        Finally
                       Me.OleDbConnection1.Close()
        End Try

    End Sub

0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20292979
try have a look at this article
http://www.homeandlearn.co.uk/NET/nets12p9.html

vbturbo
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20293016
and here from the beginning
http://www.homeandlearn.co.uk/NET/nets12p4.html

gives an easy and quick way of getting comprehension on how to work with the dataset
if you spend 15 min. walking through

vbturbo
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:RobertRFreeman
ID: 20293961
Click on your dataadapter on your form (in the components section).  In  the properties window, look at the insertcommand, updatecommand, and deletecommand properties.  These should be populated.  You can also reconfigure this adapter to try and regenerate these.  Make sure "Generate insert,update, and delete commands is enabled.
0
 

Author Comment

by:edo60
ID: 20320738
come on you guys an example of array update of your projects
regards
edo
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20321314
try have a look here

https://filedb.experts-exchange.com/incoming/ee-stuff/5731-Relations.zip 

type some data in the one of the grids or create/delete a  row(s)

then do the update made to the tables

vbturbo

NB: watch how many times i use the connection open() and close()
0
 

Author Comment

by:edo60
ID: 20323779
I can't run it
is under net 2003?
thank you
0
 
LVL 18

Accepted Solution

by:
vbturbo earned 500 total points
ID: 20323854
Hi

if you got the database then try put this code in a form (project made in vs2003)

add 2 datagrids and 1 button

Imports System.Data

Public Class Form1

    Dim con As New OleDb.OleDbConnection
    Dim ds As DataSet
    Dim daParent As OleDb.OleDbDataAdapter
    Dim daChild As OleDb.OleDbDataAdapter
    Dim sql As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Test.mdb"
        sql = "SELECT * FROM Parent"
        con.Open()

        daParent = New OleDb.OleDbDataAdapter(sql, con)
        ds = New DataSet("Parent")
        daParent.FillSchema(ds, SchemaType.Mapped, "Parent")
        daParent.Fill(ds, "Parent")

        sql = "SELECT * FROM Child"
        daChild = New OleDb.OleDbDataAdapter(sql, con)
        daChild.FillSchema(ds, SchemaType.Mapped, "Child")
        daChild.Fill(ds, "Child")

        con.Close()

        Parentgrd.DataSource = ds.Tables("Parent")
        Childgrd.DataSource = ds.Tables("Child")

        ds.Tables("Parent").Columns("ID").AutoIncrement = True
        ds.Tables("Parent").Columns("ID").AutoIncrementSeed = -1
        ds.Tables("Parent").Columns("ID").AutoIncrementSeed = +1

        ds.Tables("Child").Columns("ID").AutoIncrement = True

        SetdataRel()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Parentgrd.EndEdit()

        Dim cb As New OleDb.OleDbCommandBuilder(daParent)
        daParent.Update(ds, "Parent")

        'Childgrd.EndEdit()

        Dim cb1 As New OleDb.OleDbCommandBuilder(daChild)
        daChild.Update(ds, "Child")

        MsgBox("Data updated")
    End Sub
    Public Sub SetdataRel()
        ' Add the relation between ParentTable/ChildTable

        ds.Relations.Add(New DataRelation(relationName:="relParChi", parentColumn:=ds.Tables("Parent").Columns("ID"), _
         childColumn:=ds.Tables("Child").Columns("Foreignkey"), _
         createConstraints:=False))

        ' Set the Parent grid
        Parentgrd.DataSource = ds
        Parentgrd.DataMember = "Parent"

        ' Set the Child grid
        Childgrd.DataSource = ds
        Childgrd.DataMember = "Parent.relParChi"

    End Sub

End Class
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

729 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