By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,665 Members | 1,513 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,665 IT Pros & Developers. It's quick & easy.

Update problem ADO vbnet 2005

P: n/a
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i am doing
wrong??
Sub SaveAny()
Dim command_builder As New OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.
Aug 6 '06 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Can you tell why it "Sometimes doesnt work?, in other words does it gives no
others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
>I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i am doing
wrong??
Sub SaveAny()
Dim command_builder As New OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.


Aug 7 '06 #2

P: n/a
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words does it gives
no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
>>I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i am doing
wrong??
Sub SaveAny()
Dim command_builder As New OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.



Aug 7 '06 #3

P: n/a
Marc,

A sample would not help you there are millions of sample on Internet, can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
>Can you tell why it "Sometimes doesnt work?, in other words does it gives
no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
>>>I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i am doing
wrong??
Sub SaveAny()
Dim command_builder As New OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.




Aug 7 '06 #4

P: n/a
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on Internet, can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
>Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
>>Can you tell why it "Sometimes doesnt work?, in other words does it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i am
doing wrong??
Sub SaveAny()
Dim command_builder As New OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.




Aug 7 '06 #5

P: n/a
just for fun, let me take a wild guess and suggest that this is perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to update,
thus triggering an error much of the time. If this is the case, perhaps
you can simplify that command by including only the primary key in the
Where clause. This might introduce some concurrency issues (i.e., last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on Internet, can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words does it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i am
doing wrong??
Sub SaveAny()
Dim command_builder As New OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.

Aug 7 '06 #6

P: n/a
Adm,

But than he should in my opinion get an error instead of non updating.

Cor

<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googlegro ups.com...
just for fun, let me take a wild guess and suggest that this is perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to update,
thus triggering an error much of the time. If this is the case, perhaps
you can simplify that command by including only the primary key in the
Where clause. This might introduce some concurrency issues (i.e., last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
>Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words does it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i am
doing wrong??
Sub SaveAny()
Dim command_builder As New
OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.




Aug 7 '06 #7

P: n/a
Agreed, Cor...but to paraphrase Bill Clinton, "It depends on what the
meaning of 'doesn't work' is." I for one am interested to find out. :-)
Cor Ligthert [MVP] wrote:
Adm,

But than he should in my opinion get an error instead of non updating.

Cor

<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googlegro ups.com...
just for fun, let me take a wild guess and suggest that this is perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to update,
thus triggering an error much of the time. If this is the case, perhaps
you can simplify that command by including only the primary key in the
Where clause. This might introduce some concurrency issues (i.e., last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words does it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i am
doing wrong??
Sub SaveAny()
Dim command_builder As New
OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.


Aug 7 '06 #8

P: n/a

Hi,

Thanks for answering,

Below the code I am using

Remark:

I tested on 2 database backends

one with a lot of data: here it does not work!!!

one with a few data in it: there it works fine!!

Thanks in advance

Marc.

++++++++++++++++++++++++++++++++++++++++++++++++++ ++

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbCommandBuilder


Public Class Form1
Inherits System.Windows.Forms.Form

Dim strPath As String = Application.StartupPath & "\BeMyData.mdb"
Dim strconMyData As String = "provider=microsoft.jet.oledb.4.0; Data
Source=" & strPath

'Declaratie van het object Dataset
Private ObjectDataset As New DataSet 'Opgelet aan NEW
Dim dsMyData As New DataSet


Dim daMyData As OleDb.OleDbDataAdapter
Dim myDataTable As DataTable = New DataTable()
Dim cnMyData As New OleDb.OleDbConnection(strconMyData)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daMyData = New OleDb.OleDbDataAdapter("select * from tblAdressen
order by naam", cnMyData)
dsMyData = New DataSet
Try
daMyData.Fill(dsMyData, "tblAdressen")

dgAdressen.DataSource = dsMyData.Tables("tblAdressen")
'Binding maken voor de tekstboxen
txtNaam.DataBindings.Add("text", dsMyData.Tables("TblAdressen"),
"Naam")
txtStraat.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Straat")
txtPostcode.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Postcode")
txtPlaats.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Plaats")


Catch ex As Exception
MsgBox(ex.ToString)
End Try


'Instellen naar rij 1 eerste record te gaan
Dim rij As DataRow
rij = dsMyData.Tables("tbladressen").Rows(0)

End Sub


Private Sub btnCloseForm_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCloseForm.Click
SaveAny()
Me.Close()
End Sub


Sub SaveAny()

Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)

If dsMyData.HasChanges() = True Then
dsMyData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ', myTableName)
End If

End Sub

End Class




<ad*****@yahoo.comschreef in bericht
news:11*********************@75g2000cwc.googlegrou ps.com...
Agreed, Cor...but to paraphrase Bill Clinton, "It depends on what the
meaning of 'doesn't work' is." I for one am interested to find out. :-)
Cor Ligthert [MVP] wrote:
>Adm,

But than he should in my opinion get an error instead of non updating.

Cor

<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googlegr oups.com...
just for fun, let me take a wild guess and suggest that this is perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to update,
thus triggering an error much of the time. If this is the case, perhaps
you can simplify that command by including only the primary key in the
Where clause. This might introduce some concurrency issues (i.e., last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on
Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words does
it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i
am
doing wrong??
Sub SaveAny()
Dim command_builder As New
OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.



Aug 7 '06 #9

P: n/a
Looks like the problem is probably:

If dsMyData.HasChanges() = True Then
****dsMyData.AcceptChanges() ***
Try removing the method call to .AcceptChanges.

..AcceptChanges sets the row state of all rows in the table back to
unmodified. Therefore, when your Update command comes along, it finds
no rows to update.

This is a VERY common error in the usage of .AcceptChanges.

Let us know how it goes.

hth,

adm

Scotty wrote:
Hi,

Thanks for answering,

Below the code I am using

Remark:

I tested on 2 database backends

one with a lot of data: here it does not work!!!

one with a few data in it: there it works fine!!

Thanks in advance

Marc.

++++++++++++++++++++++++++++++++++++++++++++++++++ ++

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbCommandBuilder


Public Class Form1
Inherits System.Windows.Forms.Form

Dim strPath As String = Application.StartupPath & "\BeMyData.mdb"
Dim strconMyData As String = "provider=microsoft.jet.oledb.4.0; Data
Source=" & strPath

'Declaratie van het object Dataset
Private ObjectDataset As New DataSet 'Opgelet aan NEW
Dim dsMyData As New DataSet


Dim daMyData As OleDb.OleDbDataAdapter
Dim myDataTable As DataTable = New DataTable()
Dim cnMyData As New OleDb.OleDbConnection(strconMyData)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daMyData = New OleDb.OleDbDataAdapter("select * from tblAdressen
order by naam", cnMyData)
dsMyData = New DataSet
Try
daMyData.Fill(dsMyData, "tblAdressen")

dgAdressen.DataSource = dsMyData.Tables("tblAdressen")
'Binding maken voor de tekstboxen
txtNaam.DataBindings.Add("text", dsMyData.Tables("TblAdressen"),
"Naam")
txtStraat.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Straat")
txtPostcode.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Postcode")
txtPlaats.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Plaats")


Catch ex As Exception
MsgBox(ex.ToString)
End Try


'Instellen naar rij 1 eerste record te gaan
Dim rij As DataRow
rij = dsMyData.Tables("tbladressen").Rows(0)

End Sub


Private Sub btnCloseForm_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCloseForm.Click
SaveAny()
Me.Close()
End Sub


Sub SaveAny()

Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)

If dsMyData.HasChanges() = True Then
dsMyData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ', myTableName)
End If

End Sub

End Class




<ad*****@yahoo.comschreef in bericht
news:11*********************@75g2000cwc.googlegrou ps.com...
Agreed, Cor...but to paraphrase Bill Clinton, "It depends on what the
meaning of 'doesn't work' is." I for one am interested to find out. :-)
Cor Ligthert [MVP] wrote:
Adm,

But than he should in my opinion get an error instead of non updating.

Cor

<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googlegro ups.com...
just for fun, let me take a wild guess and suggest that this is perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to update,
thus triggering an error much of the time. If this is the case, perhaps
you can simplify that command by including only the primary key in the
Where clause. This might introduce some concurrency issues (i.e., last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on
Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words does
it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i
am
doing wrong??
Sub SaveAny()
Dim command_builder As New
OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.



Aug 7 '06 #10

P: n/a
Hi,

so I changed the code as below, but the problem is the same...
Sub SaveAny()

' Save any changes.
Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)
daMyData.Update(dsMyData.Tables("tblAdressen")) ', myTableName)
MsgBox("update uitgevoerd SavaAny 1")
End Sub

Marc.


<ad*****@yahoo.comschreef in bericht
news:11**********************@b28g2000cwb.googlegr oups.com...
Looks like the problem is probably:

If dsMyData.HasChanges() = True Then
****dsMyData.AcceptChanges() ***
Try removing the method call to .AcceptChanges.

.AcceptChanges sets the row state of all rows in the table back to
unmodified. Therefore, when your Update command comes along, it finds
no rows to update.

This is a VERY common error in the usage of .AcceptChanges.

Let us know how it goes.

hth,

adm

Scotty wrote:
>Hi,

Thanks for answering,

Below the code I am using

Remark:

I tested on 2 database backends

one with a lot of data: here it does not work!!!

one with a few data in it: there it works fine!!

Thanks in advance

Marc.

+++++++++++++++++++++++++++++++++++++++++++++++++ +++

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbCommandBuilder


Public Class Form1
Inherits System.Windows.Forms.Form

Dim strPath As String = Application.StartupPath & "\BeMyData.mdb"
Dim strconMyData As String = "provider=microsoft.jet.oledb.4.0; Data
Source=" & strPath

'Declaratie van het object Dataset
Private ObjectDataset As New DataSet 'Opgelet aan NEW
Dim dsMyData As New DataSet


Dim daMyData As OleDb.OleDbDataAdapter
Dim myDataTable As DataTable = New DataTable()
Dim cnMyData As New OleDb.OleDbConnection(strconMyData)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daMyData = New OleDb.OleDbDataAdapter("select * from tblAdressen
order by naam", cnMyData)
dsMyData = New DataSet
Try
daMyData.Fill(dsMyData, "tblAdressen")

dgAdressen.DataSource = dsMyData.Tables("tblAdressen")
'Binding maken voor de tekstboxen
txtNaam.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"),
"Naam")
txtStraat.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Straat")
txtPostcode.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Postcode")
txtPlaats.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Plaats")


Catch ex As Exception
MsgBox(ex.ToString)
End Try


'Instellen naar rij 1 eerste record te gaan
Dim rij As DataRow
rij = dsMyData.Tables("tbladressen").Rows(0)

End Sub


Private Sub btnCloseForm_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles btnCloseForm.Click
SaveAny()
Me.Close()
End Sub


Sub SaveAny()

Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)

If dsMyData.HasChanges() = True Then
dsMyData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ',
myTableName)
End If

End Sub

End Class




<ad*****@yahoo.comschreef in bericht
news:11*********************@75g2000cwc.googlegro ups.com...
Agreed, Cor...but to paraphrase Bill Clinton, "It depends on what the
meaning of 'doesn't work' is." I for one am interested to find out. :-)
Cor Ligthert [MVP] wrote:
Adm,

But than he should in my opinion get an error instead of non updating.

Cor

<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googlegr oups.com...
just for fun, let me take a wild guess and suggest that this is
perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to
update,
thus triggering an error much of the time. If this is the case,
perhaps
you can simplify that command by including only the primary key in
the
Where clause. This might introduce some concurrency issues (i.e.,
last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on
Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in
bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words
does
it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what
i
am
doing wrong??
Sub SaveAny()
Dim command_builder As New
OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.




Aug 7 '06 #11

P: n/a
Scotty

Do that remove of the acceptchanges as adm already wrote
(It set all update rowstates to notchanges and something more)

and put before that if haschanges

BindingContext(dsMyData.Tables("TblAdressen")).End CurrentEdit()

That is to push the text in the last edited textbox into the datatable, what
will probably be your next problem.

I hope this helps,

Cor
"Scotty" <xx****@nothing.beschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
>
Hi,

Thanks for answering,

Below the code I am using

Remark:

I tested on 2 database backends

one with a lot of data: here it does not work!!!

one with a few data in it: there it works fine!!

Thanks in advance

Marc.

++++++++++++++++++++++++++++++++++++++++++++++++++ ++

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbCommandBuilder


Public Class Form1
Inherits System.Windows.Forms.Form

Dim strPath As String = Application.StartupPath & "\BeMyData.mdb"
Dim strconMyData As String = "provider=microsoft.jet.oledb.4.0; Data
Source=" & strPath

'Declaratie van het object Dataset
Private ObjectDataset As New DataSet 'Opgelet aan NEW
Dim dsMyData As New DataSet


Dim daMyData As OleDb.OleDbDataAdapter
Dim myDataTable As DataTable = New DataTable()
Dim cnMyData As New OleDb.OleDbConnection(strconMyData)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daMyData = New OleDb.OleDbDataAdapter("select * from tblAdressen
order by naam", cnMyData)
dsMyData = New DataSet
Try
daMyData.Fill(dsMyData, "tblAdressen")

dgAdressen.DataSource = dsMyData.Tables("tblAdressen")
'Binding maken voor de tekstboxen
txtNaam.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Naam")
txtStraat.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Straat")
txtPostcode.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Postcode")
txtPlaats.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Plaats")


Catch ex As Exception
MsgBox(ex.ToString)
End Try


'Instellen naar rij 1 eerste record te gaan
Dim rij As DataRow
rij = dsMyData.Tables("tbladressen").Rows(0)

End Sub


Private Sub btnCloseForm_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCloseForm.Click
SaveAny()
Me.Close()
End Sub


Sub SaveAny()

Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)

If dsMyData.HasChanges() = True Then
dsMyData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ', myTableName)
End If

End Sub

End Class




<ad*****@yahoo.comschreef in bericht
news:11*********************@75g2000cwc.googlegrou ps.com...
>Agreed, Cor...but to paraphrase Bill Clinton, "It depends on what the
meaning of 'doesn't work' is." I for one am interested to find out. :-)
Cor Ligthert [MVP] wrote:
>>Adm,

But than he should in my opinion get an error instead of non updating.

Cor

<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googleg roups.com...
just for fun, let me take a wild guess and suggest that this is
perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to
update,
thus triggering an error much of the time. If this is the case,
perhaps
you can simplify that command by including only the primary key in the
Where clause. This might introduce some concurrency issues (i.e., last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on
Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words does
it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
>I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i
am
doing wrong??
>
>
Sub SaveAny()
>
>
Dim command_builder As New
OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
>
>
End Sub
>
>
Thanks for helping
>
Marc.
>
>




Aug 7 '06 #12

P: n/a

Hmm. If Cor's final tip does not work:

- Are you getting any errors, or is it just that modified records are
not appearing in the database?

- Have you set breakpoints to watch the program flow? Are you certain
that the update command is being executed.

- Again, you may wish to analyze the SQL text of the Update command to
see if you can make any sense of it. Perhaps it will tell you where the
problem lies.

Continue posting!

adm


Scotty wrote:
Hi,

Thanks for answering,

Below the code I am using

Remark:

I tested on 2 database backends

one with a lot of data: here it does not work!!!

one with a few data in it: there it works fine!!

Thanks in advance

Marc.

++++++++++++++++++++++++++++++++++++++++++++++++++ ++

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbCommandBuilder


Public Class Form1
Inherits System.Windows.Forms.Form

Dim strPath As String = Application.StartupPath & "\BeMyData.mdb"
Dim strconMyData As String = "provider=microsoft.jet.oledb.4.0; Data
Source=" & strPath

'Declaratie van het object Dataset
Private ObjectDataset As New DataSet 'Opgelet aan NEW
Dim dsMyData As New DataSet


Dim daMyData As OleDb.OleDbDataAdapter
Dim myDataTable As DataTable = New DataTable()
Dim cnMyData As New OleDb.OleDbConnection(strconMyData)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daMyData = New OleDb.OleDbDataAdapter("select * from tblAdressen
order by naam", cnMyData)
dsMyData = New DataSet
Try
daMyData.Fill(dsMyData, "tblAdressen")

dgAdressen.DataSource = dsMyData.Tables("tblAdressen")
'Binding maken voor de tekstboxen
txtNaam.DataBindings.Add("text", dsMyData.Tables("TblAdressen"),
"Naam")
txtStraat.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Straat")
txtPostcode.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Postcode")
txtPlaats.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Plaats")


Catch ex As Exception
MsgBox(ex.ToString)
End Try


'Instellen naar rij 1 eerste record te gaan
Dim rij As DataRow
rij = dsMyData.Tables("tbladressen").Rows(0)

End Sub


Private Sub btnCloseForm_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCloseForm.Click
SaveAny()
Me.Close()
End Sub


Sub SaveAny()

Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)

If dsMyData.HasChanges() = True Then
dsMyData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ', myTableName)
End If

End Sub

End Class




<ad*****@yahoo.comschreef in bericht
news:11*********************@75g2000cwc.googlegrou ps.com...
Agreed, Cor...but to paraphrase Bill Clinton, "It depends on what the
meaning of 'doesn't work' is." I for one am interested to find out. :-)
Cor Ligthert [MVP] wrote:
Adm,

But than he should in my opinion get an error instead of non updating.

Cor

<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googlegro ups.com...
just for fun, let me take a wild guess and suggest that this is perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to update,
thus triggering an error much of the time. If this is the case, perhaps
you can simplify that command by including only the primary key in the
Where clause. This might introduce some concurrency issues (i.e., last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on
Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words does
it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i
am
doing wrong??
Sub SaveAny()
Dim command_builder As New
OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.



Aug 7 '06 #13

P: n/a


Hi,

I tried also this code, but no difference no update is done

Sub SaveAny()

' Save any changes.
Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)
BindingContext(dsMyData.Tables("TblAdressen")).End CurrentEdit()
If dsMyData.HasChanges() = True Then
' dsActionData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ', myTableName)
MsgBox("update uitgevoerd SavaAny 2")

End If

End Sub

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
Scotty

Do that remove of the acceptchanges as adm already wrote
(It set all update rowstates to notchanges and something more)

and put before that if haschanges

BindingContext(dsMyData.Tables("TblAdressen")).End CurrentEdit()

That is to push the text in the last edited textbox into the datatable,
what will probably be your next problem.

I hope this helps,

Cor
"Scotty" <xx****@nothing.beschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>
Hi,

Thanks for answering,

Below the code I am using

Remark:

I tested on 2 database backends

one with a lot of data: here it does not work!!!

one with a few data in it: there it works fine!!

Thanks in advance

Marc.

+++++++++++++++++++++++++++++++++++++++++++++++++ +++

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbCommandBuilder


Public Class Form1
Inherits System.Windows.Forms.Form

Dim strPath As String = Application.StartupPath & "\BeMyData.mdb"
Dim strconMyData As String = "provider=microsoft.jet.oledb.4.0; Data
Source=" & strPath

'Declaratie van het object Dataset
Private ObjectDataset As New DataSet 'Opgelet aan NEW
Dim dsMyData As New DataSet


Dim daMyData As OleDb.OleDbDataAdapter
Dim myDataTable As DataTable = New DataTable()
Dim cnMyData As New OleDb.OleDbConnection(strconMyData)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daMyData = New OleDb.OleDbDataAdapter("select * from tblAdressen
order by naam", cnMyData)
dsMyData = New DataSet
Try
daMyData.Fill(dsMyData, "tblAdressen")

dgAdressen.DataSource = dsMyData.Tables("tblAdressen")
'Binding maken voor de tekstboxen
txtNaam.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Naam")
txtStraat.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Straat")
txtPostcode.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Postcode")
txtPlaats.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Plaats")


Catch ex As Exception
MsgBox(ex.ToString)
End Try


'Instellen naar rij 1 eerste record te gaan
Dim rij As DataRow
rij = dsMyData.Tables("tbladressen").Rows(0)

End Sub


Private Sub btnCloseForm_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCloseForm.Click
SaveAny()
Me.Close()
End Sub


Sub SaveAny()

Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)

If dsMyData.HasChanges() = True Then
dsMyData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ',
myTableName)
End If

End Sub

End Class




<ad*****@yahoo.comschreef in bericht
news:11*********************@75g2000cwc.googlegro ups.com...
>>Agreed, Cor...but to paraphrase Bill Clinton, "It depends on what the
meaning of 'doesn't work' is." I for one am interested to find out. :-)
Cor Ligthert [MVP] wrote:
Adm,

But than he should in my opinion get an error instead of non updating.

Cor

<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.google groups.com...
just for fun, let me take a wild guess and suggest that this is
perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to
update,
thus triggering an error much of the time. If this is the case,
perhaps
you can simplify that command by including only the primary key in
the
Where clause. This might introduce some concurrency issues (i.e.,
last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on
Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl.. .
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in
bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words does
it
gives no others or what does not work.
>
Cor
>
"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl.. .
>>I like to have a good insert, update and delete code
>The code below sometimes workl ok sometimes doesnt work, what i
>am
>doing wrong??
>>
>>
>Sub SaveAny()
>>
>>
> Dim command_builder As New
>OleDb.OleDbCommandBuilder(daOrders)
> ' Save any changes.
> daOrders.Update(dsOrders, "tblOrders")
>>
>>
> End Sub
>>
>>
>Thanks for helping
>>
>Marc.
>>
>>
>
>




Aug 7 '06 #14

P: n/a
Scotty,

You say it is working on one computer, but "It *should* not work in the way
as you have showed it to us in your first sample on any computer".

This is very strange

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:O4**************@TK2MSFTNGP03.phx.gbl...
>

Hi,

I tried also this code, but no difference no update is done

Sub SaveAny()

' Save any changes.
Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)
BindingContext(dsMyData.Tables("TblAdressen")).End CurrentEdit()
If dsMyData.HasChanges() = True Then
' dsActionData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ', myTableName)
MsgBox("update uitgevoerd SavaAny 2")

End If

End Sub

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
>Scotty

Do that remove of the acceptchanges as adm already wrote
(It set all update rowstates to notchanges and something more)

and put before that if haschanges

BindingContext(dsMyData.Tables("TblAdressen")).En dCurrentEdit()

That is to push the text in the last edited textbox into the datatable,
what will probably be your next problem.

I hope this helps,

Cor
"Scotty" <xx****@nothing.beschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>>
Hi,

Thanks for answering,

Below the code I am using

Remark:

I tested on 2 database backends

one with a lot of data: here it does not work!!!

one with a few data in it: there it works fine!!

Thanks in advance

Marc.

++++++++++++++++++++++++++++++++++++++++++++++++ ++++

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbCommandBuilder


Public Class Form1
Inherits System.Windows.Forms.Form

Dim strPath As String = Application.StartupPath & "\BeMyData.mdb"
Dim strconMyData As String = "provider=microsoft.jet.oledb.4.0; Data
Source=" & strPath

'Declaratie van het object Dataset
Private ObjectDataset As New DataSet 'Opgelet aan NEW
Dim dsMyData As New DataSet


Dim daMyData As OleDb.OleDbDataAdapter
Dim myDataTable As DataTable = New DataTable()
Dim cnMyData As New OleDb.OleDbConnection(strconMyData)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daMyData = New OleDb.OleDbDataAdapter("select * from tblAdressen
order by naam", cnMyData)
dsMyData = New DataSet
Try
daMyData.Fill(dsMyData, "tblAdressen")

dgAdressen.DataSource = dsMyData.Tables("tblAdressen")
'Binding maken voor de tekstboxen
txtNaam.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Naam")
txtStraat.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Straat")
txtPostcode.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Postcode")
txtPlaats.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Plaats")


Catch ex As Exception
MsgBox(ex.ToString)
End Try


'Instellen naar rij 1 eerste record te gaan
Dim rij As DataRow
rij = dsMyData.Tables("tbladressen").Rows(0)

End Sub


Private Sub btnCloseForm_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCloseForm.Click
SaveAny()
Me.Close()
End Sub


Sub SaveAny()

Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)

If dsMyData.HasChanges() = True Then
dsMyData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ',
myTableName)
End If

End Sub

End Class




<ad*****@yahoo.comschreef in bericht
news:11*********************@75g2000cwc.googlegr oups.com...
Agreed, Cor...but to paraphrase Bill Clinton, "It depends on what the
meaning of 'doesn't work' is." I for one am interested to find out. :-)
Cor Ligthert [MVP] wrote:
Adm,
>
But than he should in my opinion get an error instead of non updating.
>
Cor
>
<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googl egroups.com...
just for fun, let me take a wild guess and suggest that this is
perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to
update,
thus triggering an error much of the time. If this is the case,
perhaps
you can simplify that command by including only the primary key in
the
Where clause. This might introduce some concurrency issues (i.e.,
last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,
>
Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code
>
Best regards
>
Marc,
Action-Data
>
>
>
"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl.. .
Marc,

A sample would not help you there are millions of sample on
Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl. ..
Hi Cor,
>
Thanks for answering,
I don't have any adea why it does not work sometimes
>
The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?
>
Many thanks in advance,
Marc.
>
>
>
>
>
"Cor Ligthert [MVP]" <no************@planet.nlschreef in
bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl.. .
>Can you tell why it "Sometimes doesnt work?, in other words
>does it
>gives no others or what does not work.
>>
>Cor
>>
>"Scotty" <xx****@nothing.beschreef in bericht
>news:ut**************@TK2MSFTNGP02.phx.gbl. ..
>>>I like to have a good insert, update and delete code
>>The code below sometimes workl ok sometimes doesnt work, what
>>i am
>>doing wrong??
>>>
>>>
>>Sub SaveAny()
>>>
>>>
>> Dim command_builder As New
>>OleDb.OleDbCommandBuilder(daOrders)
>> ' Save any changes.
>> daOrders.Update(dsOrders, "tblOrders")
>>>
>>>
>> End Sub
>>>
>>>
>>Thanks for helping
>>>
>>Marc.
>>>
>>>
>>
>>
>
>




Aug 7 '06 #15

P: n/a
Hi,

I have rewritten my code from beginning and now the updating is working
fine,
I will write the other code and controlling one by one if the problem would
happen again.

Many thanks again for all who has answered on the newsgroup.
Best regards
Marc.


<ad*****@yahoo.comschreef in bericht
news:11*********************@n13g2000cwa.googlegro ups.com...
>
Hmm. If Cor's final tip does not work:

- Are you getting any errors, or is it just that modified records are
not appearing in the database?

- Have you set breakpoints to watch the program flow? Are you certain
that the update command is being executed.

- Again, you may wish to analyze the SQL text of the Update command to
see if you can make any sense of it. Perhaps it will tell you where the
problem lies.

Continue posting!

adm


Scotty wrote:
>Hi,

Thanks for answering,

Below the code I am using

Remark:

I tested on 2 database backends

one with a lot of data: here it does not work!!!

one with a few data in it: there it works fine!!

Thanks in advance

Marc.

+++++++++++++++++++++++++++++++++++++++++++++++++ +++

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbCommandBuilder


Public Class Form1
Inherits System.Windows.Forms.Form

Dim strPath As String = Application.StartupPath & "\BeMyData.mdb"
Dim strconMyData As String = "provider=microsoft.jet.oledb.4.0; Data
Source=" & strPath

'Declaratie van het object Dataset
Private ObjectDataset As New DataSet 'Opgelet aan NEW
Dim dsMyData As New DataSet


Dim daMyData As OleDb.OleDbDataAdapter
Dim myDataTable As DataTable = New DataTable()
Dim cnMyData As New OleDb.OleDbConnection(strconMyData)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daMyData = New OleDb.OleDbDataAdapter("select * from tblAdressen
order by naam", cnMyData)
dsMyData = New DataSet
Try
daMyData.Fill(dsMyData, "tblAdressen")

dgAdressen.DataSource = dsMyData.Tables("tblAdressen")
'Binding maken voor de tekstboxen
txtNaam.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"),
"Naam")
txtStraat.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Straat")
txtPostcode.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Postcode")
txtPlaats.DataBindings.Add("text",
dsMyData.Tables("TblAdressen"), "Plaats")


Catch ex As Exception
MsgBox(ex.ToString)
End Try


'Instellen naar rij 1 eerste record te gaan
Dim rij As DataRow
rij = dsMyData.Tables("tbladressen").Rows(0)

End Sub


Private Sub btnCloseForm_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles btnCloseForm.Click
SaveAny()
Me.Close()
End Sub


Sub SaveAny()

Dim command_builder As New OleDb.OleDbCommandBuilder(daMyData)

If dsMyData.HasChanges() = True Then
dsMyData.AcceptChanges()
daMyData.Update(dsMyData.Tables("tblAdressen")) ',
myTableName)
End If

End Sub

End Class




<ad*****@yahoo.comschreef in bericht
news:11*********************@75g2000cwc.googlegro ups.com...
Agreed, Cor...but to paraphrase Bill Clinton, "It depends on what the
meaning of 'doesn't work' is." I for one am interested to find out. :-)
Cor Ligthert [MVP] wrote:
Adm,

But than he should in my opinion get an error instead of non updating.

Cor

<ad*****@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googlegr oups.com...
just for fun, let me take a wild guess and suggest that this is
perhaps
due to optimistic record locking.

scotty, before executing the .Update command, determine what the SQL
text of the command is. See if the 'WHERE' clause is really long and
includes every one of the fields in your table. In such cases, the
Where clause is so specific that it fails to find the record to
update,
thus triggering an error much of the time. If this is the case,
perhaps
you can simplify that command by including only the primary key in
the
Where clause. This might introduce some concurrency issues (i.e.,
last
one in will always win), but it may also resolve your error.

If this isn't the situation and my shot in the dark missed the mark,
please post more details on the error and your code.

adm

Scotty wrote:
Hi Cor,

Thanks for willing help me,
This evening (Belgium time)I will send you more info about my code

Best regards

Marc,
Action-Data

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:O9**************@TK2MSFTNGP04.phx.gbl...
Marc,

A sample would not help you there are millions of sample on
Internet,
can
you show the code where you do the update.

Cor
"Action-Data" <Ma**@nomails.invalidschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

Thanks for answering,
I don't have any adea why it does not work sometimes

The connection is coded in ADO (I did not use the grafical way)
Do you have a good sample for me?

Many thanks in advance,
Marc.

"Cor Ligthert [MVP]" <no************@planet.nlschreef in
bericht
news:Ov**************@TK2MSFTNGP02.phx.gbl...
Can you tell why it "Sometimes doesnt work?, in other words
does
it
gives no others or what does not work.

Cor

"Scotty" <xx****@nothing.beschreef in bericht
news:ut**************@TK2MSFTNGP02.phx.gbl...
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what
i
am
doing wrong??
Sub SaveAny()
Dim command_builder As New
OleDb.OleDbCommandBuilder(daOrders)
' Save any changes.
daOrders.Update(dsOrders, "tblOrders")
End Sub
Thanks for helping

Marc.




Aug 8 '06 #16

This discussion thread is closed

Replies have been disabled for this discussion.