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. 15 1786
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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. > >
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.
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. >> >> > >
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. >>> >>> >> >> > >
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: KT |
last post by:
Do we have any idea how long VBNet is going to be supported?
Being a hobbyist VB6 user I am only interested in creating windows based
applications and have no need for web services, asp etc. I...
|
by: marfi95 |
last post by:
I want to implement into my application a mechanism to retrieve the
"latest updates" to my app. I'm looking for various ways to accomplish
this and how to get around the fact that you are running...
|
by: Jon |
last post by:
I am trying to convert an application from VB to VB.Net. the application is
large (400 + Screens) and (175+ reports).
I am a visual learner meaning if I found examples how to do something in VB...
|
by: Ivan |
last post by:
Thanks to answer topic previous!!!!
I use this script to update one table
MERGE INTO EIS.CLI_HISTORY TXN
USING EIS.CLI_MAPING CLI
ON TXN.CLIENTID = CLI.CLIENTID
WHEN MATCHED AND...
|
by: lmnorms1 |
last post by:
Hello,
I am trying to update an access database record date field that matches
a specific date. The code is not working. Anyone have any advice?
Here is the code:
Dim gConnString As String =...
|
by: lmnorms1 |
last post by:
Hello,
I am looking to update a record that was read in with OleDbDataReader.
I have the record in reader but now with the reader connection open;
how do I update it.
Any advice would be...
|
by: mike11d11 |
last post by:
I'm doing a simple TableAdapter.Fill filling my datatable from a view
within a SQL database. for some reason it is timing out after 30
seconds and I cant seem to find out where in vb.net 2005 I...
|
by: JamieHowarth0 |
last post by:
Hi folks,
I'm making a snazzy VB.NET GUI as part of my contract for an asset management firm and it incorporates a TreeView control which I am using to graphically display details of locations,...
|
by: CommonElements |
last post by:
Hi,
1. I am using Visual Studio.NET 2005 C# Win Form
2. I have setup a database connection to my Access Database using ADO.NET
3. On my system timer I have the following code to execute every 1...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |