Home All Groups Group Topic Archive Search About

ADO.NET - Problem with Insert-, Delete- and UpdateCommand

Author
14 Feb 2007 9:17 AM
fiaolle
Hi

I'm new to ADO in Visual Basic.Net and have problems with updating the
DataSet after I have done ExecuteNonQuery.
I'm using the code below

Private Sub cmdDel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDel.Click
        Me.OleDbConn.Open()
        Me.OleDbDAFilmKat.DeleteCommand.Parameters(0).Value = Me.txtNr.Text
        Me.OleDbDAFilmKat.DeleteCommand.ExecuteNonQuery()
        Me.OleDbDAFilmKat.Update(DSFilm, "Film")
        MaxRows = DSFilm.Tables("Film").Rows.Count
        Me.OleDbConn.Close()
End sub

After this, when I'm using the DataSet DSFilm the DataSet isn't updated. But
when I restart the program the record is gone.
I have seen example where I should use Me.OleDbDAFilmKat.Fill(DSFilm,
"Film") instead, but it didn't help. I have also seen articles there I
should use this code
Dim oRow as DataRow
oRow = Me.DSFilm.Tables("Film").Rows(0)
oRow.Delete()
Then after that, use the DeleteCommand for the DataAdapter.
Do I have to do this above to delete a row in the Dataset, then use the
DataAdapter's DeleteCommand to delete a row in the Database. Isn't there
another way.
I have the same problem with InsertCommand and UpdateCommand.

Please Help !!!
Fia

Author
14 Feb 2007 12:39 PM
Kerry Moorman
Fia,

You need to use the data adapter's Update command to handle all changes
(inserts, updates, deletes) to the database.

Kerry Moorman


Show quote
"fiaolle" wrote:

> Hi
>
> I'm new to ADO in Visual Basic.Net and have problems with updating the
> DataSet after I have done ExecuteNonQuery.
> I'm using the code below
>
> Private Sub cmdDel_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdDel.Click
>         Me.OleDbConn.Open()
>         Me.OleDbDAFilmKat.DeleteCommand.Parameters(0).Value = Me.txtNr.Text
>         Me.OleDbDAFilmKat.DeleteCommand.ExecuteNonQuery()
>         Me.OleDbDAFilmKat.Update(DSFilm, "Film")
>         MaxRows = DSFilm.Tables("Film").Rows.Count
>         Me.OleDbConn.Close()
> End sub
>
> After this, when I'm using the DataSet DSFilm the DataSet isn't updated. But
> when I restart the program the record is gone.
> I have seen example where I should use Me.OleDbDAFilmKat.Fill(DSFilm,
> "Film") instead, but it didn't help. I have also seen articles there I
> should use this code
> Dim oRow as DataRow
> oRow = Me.DSFilm.Tables("Film").Rows(0)
> oRow.Delete()
> Then after that, use the DeleteCommand for the DataAdapter.
> Do I have to do this above to delete a row in the Dataset, then use the
> DataAdapter's DeleteCommand to delete a row in the Database. Isn't there
> another way.
> I have the same problem with InsertCommand and UpdateCommand.
>
> Please Help !!!
> Fia
>
>
>
Author
14 Feb 2007 2:31 PM
fiaolle
Hi
Thank's for your answer but I think I am using the DataAdapter's Update. In
my code the DataAdapter is OleDbDAFilmKat. I'm not sure what you mean.

Fia
Show quote
"Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message
news:2F1AADA6-9C63-47F1-BF6B-B01EC2194B33@microsoft.com...
> Fia,
>
> You need to use the data adapter's Update command to handle all changes
> (inserts, updates, deletes) to the database.
>
> Kerry Moorman
>
>
> "fiaolle" wrote:
>
> > Hi
> >
> > I'm new to ADO in Visual Basic.Net and have problems with updating the
> > DataSet after I have done ExecuteNonQuery.
> > I'm using the code below
> >
> > Private Sub cmdDel_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles cmdDel.Click
> >         Me.OleDbConn.Open()
> >         Me.OleDbDAFilmKat.DeleteCommand.Parameters(0).Value =
Me.txtNr.Text
Show quote
> >         Me.OleDbDAFilmKat.DeleteCommand.ExecuteNonQuery()
> >         Me.OleDbDAFilmKat.Update(DSFilm, "Film")
> >         MaxRows = DSFilm.Tables("Film").Rows.Count
> >         Me.OleDbConn.Close()
> > End sub
> >
> > After this, when I'm using the DataSet DSFilm the DataSet isn't updated.
But
> > when I restart the program the record is gone.
> > I have seen example where I should use Me.OleDbDAFilmKat.Fill(DSFilm,
> > "Film") instead, but it didn't help. I have also seen articles there I
> > should use this code
> > Dim oRow as DataRow
> > oRow = Me.DSFilm.Tables("Film").Rows(0)
> > oRow.Delete()
> > Then after that, use the DeleteCommand for the DataAdapter.
> > Do I have to do this above to delete a row in the Dataset, then use the
> > DataAdapter's DeleteCommand to delete a row in the Database. Isn't there
> > another way.
> > I have the same problem with InsertCommand and UpdateCommand.
> >
> > Please Help !!!
> > Fia
> >
> >
> >
Author
14 Feb 2007 2:57 PM
Kerry Moorman
Fia,

I meant don't call Me.OleDbDAFilmKat.DeleteCommand.ExecuteNonQuery().

Just call the data adapter's Update method. The data adapter decides to call
your Insert, Update or DeleteCommand based on the state of a particular row.

Kerry Moorman


Show quote
"fiaolle" wrote:

> Hi
> Thank's for your answer but I think I am using the DataAdapter's Update. In
> my code the DataAdapter is OleDbDAFilmKat. I'm not sure what you mean.
>
> Fia
> "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message
> news:2F1AADA6-9C63-47F1-BF6B-B01EC2194B33@microsoft.com...
> > Fia,
> >
> > You need to use the data adapter's Update command to handle all changes
> > (inserts, updates, deletes) to the database.
> >
> > Kerry Moorman
> >
> >
> > "fiaolle" wrote:
> >
> > > Hi
> > >
> > > I'm new to ADO in Visual Basic.Net and have problems with updating the
> > > DataSet after I have done ExecuteNonQuery.
> > > I'm using the code below
> > >
> > > Private Sub cmdDel_Click(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles cmdDel.Click
> > >         Me.OleDbConn.Open()
> > >         Me.OleDbDAFilmKat.DeleteCommand.Parameters(0).Value =
> Me.txtNr.Text
> > >         Me.OleDbDAFilmKat.DeleteCommand.ExecuteNonQuery()
> > >         Me.OleDbDAFilmKat.Update(DSFilm, "Film")
> > >         MaxRows = DSFilm.Tables("Film").Rows.Count
> > >         Me.OleDbConn.Close()
> > > End sub
> > >
> > > After this, when I'm using the DataSet DSFilm the DataSet isn't updated.
> But
> > > when I restart the program the record is gone.
> > > I have seen example where I should use Me.OleDbDAFilmKat.Fill(DSFilm,
> > > "Film") instead, but it didn't help. I have also seen articles there I
> > > should use this code
> > > Dim oRow as DataRow
> > > oRow = Me.DSFilm.Tables("Film").Rows(0)
> > > oRow.Delete()
> > > Then after that, use the DeleteCommand for the DataAdapter.
> > > Do I have to do this above to delete a row in the Dataset, then use the
> > > DataAdapter's DeleteCommand to delete a row in the Database. Isn't there
> > > another way.
> > > I have the same problem with InsertCommand and UpdateCommand.
> > >
> > > Please Help !!!
> > > Fia
> > >
> > >
> > >
>
>
>

AddThis Social Bookmark Button