DataRowState.Modified just by navigation??

J

John Wynstra

I’m running into a problem with a dataset where the columns are bound to
text boxes on a form. By merely navigating through the records using a
bindingmanagerbase, the rowstate for each row that I navigate through
changes to modified even though I have not edited the data. What would
cause this? I have included the relevant CODE.


'FORM DATASET DECLARED
Friend dsarticlelist As New DataSet()
Friend issue_id As String
Dim bmgrid As BindingManagerBase


'LOAD THE FORM, FILL DATASET, BIND TO CONTROLS
Private Sub frmArticle_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

loadarticles(Me.issue_id)
Me.BindArticleDataSettofields()
bmgrid = BindingContext(Me.dsarticlelist, "ixu_articles")
'Me.loadauthorsubjects(txtArticle_id.Text)
End Sub

Private Sub loadarticles(ByVal i_id As String)
dsarticlelist = ixudata.GetArticles(i_id)
End Sub

'SET ISSUE_ID THAT IS USED TO GET ARTICLES
Public Sub SetIssue_ID(ByVal i_id As String)
Me.issue_id = i_id
End Sub

'BIND DATASET TO CONTROLS
Private Sub BindArticleDataSettofields()
Me.txtTitle.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.title"))
Me.txtSummary.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.summary"))
Me.txtDoc_Type.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.doc_type"))
Me.txtPage.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.page"))
Me.txturl.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.url"))
Me.txtIssue_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.issue_id"))
Me.txtArticle_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.article_id"))
End Sub

'MOVE FORWARD THROUGH DATASET
Private Sub MoveNext()
Me.bmgrid.Position += 1
End Sub

'MOVE BACKWARD THROUGH DATASET
Private Sub MovePrevious()
Me.bmgrid.Position -= 1
End Sub

'EVENT THAT TRIGGERS MOVE FORWARD
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click
Me.MoveNext()
End Sub
'EVENT THAT TRIGGERS MOVE BACKWARD
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnPrevious.Click
Me.MovePrevious()
End Sub

'DISPLAYs ROWS THAT HAVE BEEN MODIFIED IN A DATAGRID
Private Sub btnSave_issue_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSave_issue.Click

Try
If Me.dsarticlelist.HasChanges Then
Dim myds_u_articles As New DataSet()
myds_u_articles =
Me.dsarticlelist.GetChanges(DataRowState.Modified)
Me.dgdchanges.DataSource = myds_u_articles

'If (ixudata.UpdateArticlesinDB(myds_u_articles)) Then
'Me.dsarticlelist.AcceptChanges()
'Else
' Me.dsarticlelist.RejectChanges()
'End If
End If
Catch
UnhandledExceptionHandler()

End Try
End Sub
 
W

William Ryan eMVP

John:

Before you make a move anywhere...insert a
Debug.Assert(Me.dsarticlelist.HasChanges) and see if it fails.

I can't tell from here but do you have any events in your textbox controls
that chnage the data or anything? If you just navigate forward once, do
nothing else, does it show just one row modified for instance? Is there
anything else going on?
 
J

John Wynstra

William,

Thanks for taking the time to reply. The Debug.Assert fails.

I don't have any events associated with these textbox controls.

If I navigate forward once, and do nothing else, it shows just one row
modified, and if I move forward twice and do nothing, it shows two rows
modified, etc. I do not have anything else going on that I have been
able to put my finger on.

I am using ms oledb provider to connect to an Oracle database on the
backend. I have wondered if there is some type conversion that is
happening to the data as it is presented in the textbox which actually
changes the data. The fields in the oracle table are mostly varchar,
but two are integer fields.

By the way, I have also tested setting the "read only" property to true
for each of the text boxes displaying the dataset, and I still get
haschanges(DataRowState.Modified) for each row that I navigate through.
I'm baffled.
 
W

William Ryan eMVP

John:

Ok, if it fails then we're dealing with a clean set. Is there a new row or
anything like that?

I've seen this once when I tried using a bindingcontext and set a combobox's
databindings and used the bindigncontext for it, but also set the datasource
and valuemember.

What is me.Issue_Id? Use a search and find everything hwere you are
referencing the datatable...make sure nothing behind the scenes or something
that you meant to comment out is it.

Another thing, one by one Set the ReadOnly property of the underlying
datacolumn (not the textbox) to true --- if something is changing the value
outside of the ui, readonly on the textbox won't catch it, then you'll spot
it this way. If every column is readonly, then nothing will be able to be
edited, so do it one at a time. Also, don't undo it each time.. First time
set Column[0].ReadOnly = True next set 0 & 1, next 0,1,2. This is
redundant, but it will help make things certain that it's not a calculation
or something.
 
J

John Wynstra

No new rows are added.

The Issue_Id is set by the calling form. The Issue_ID is used as the
basis for retreiving the articles from the data source. Here is the
function from the data class which is called during form_load.

Public Shared Function GetArticles(ByVal issue_id As String) As DataSet

Dim sSQL = "Select article_id, title, page, doc_type,
summary,issue_id,url FROM Articles where issue_id = '" & issue_id & "'
Order by page ASC"
Dim conIXU As OleDbConnection = GetIXUConnection(CONN)
Dim daArticles As New OleDbDataAdapter(sSQL, conIXU)
Dim dsArticles As New DataSet()
daArticles.Fill(dsArticles, "ixu_articles")
conIXU.Close()
Return dsArticles
End Function

When I set the Article_ID(primary key for table) column to read only the
navigation will not move forward. When I set any of the other columns
to readonly, the app throws an "Error Number:5 occured. Description:
Column'TITLE' is read only. Source:System.Data" message whenever I try
to move forward. So somehow, the simple act of moving to the next row
is causing a change in the data.

Still baffled.
John:

Ok, if it fails then we're dealing with a clean set. Is there a new row or
anything like that?

I've seen this once when I tried using a bindingcontext and set a combobox's
databindings and used the bindigncontext for it, but also set the datasource
and valuemember.

What is me.Issue_Id? Use a search and find everything hwere you are
referencing the datatable...make sure nothing behind the scenes or something
that you meant to comment out is it.

Another thing, one by one Set the ReadOnly property of the underlying
datacolumn (not the textbox) to true --- if something is changing the value
outside of the ui, readonly on the textbox won't catch it, then you'll spot
it this way. If every column is readonly, then nothing will be able to be
edited, so do it one at a time. Also, don't undo it each time.. First time
set Column[0].ReadOnly = True next set 0 & 1, next 0,1,2. This is
redundant, but it will help make things certain that it's not a calculation
or something.
William,

Thanks for taking the time to reply. The Debug.Assert fails.

I don't have any events associated with these textbox controls.

If I navigate forward once, and do nothing else, it shows just one row
modified, and if I move forward twice and do nothing, it shows two rows
modified, etc. I do not have anything else going on that I have been
able to put my finger on.

I am using ms oledb provider to connect to an Oracle database on the
backend. I have wondered if there is some type conversion that is
happening to the data as it is presented in the textbox which actually
changes the data. The fields in the oracle table are mostly varchar,
but two are integer fields.

By the way, I have also tested setting the "read only" property to true
for each of the text boxes displaying the dataset, and I still get
haschanges(DataRowState.Modified) for each row that I navigate through.
I'm baffled.


controls
 
G

Greg

We saw a lot of stuff like this. In our case, most of the time we were
masking data in textboxes, which is truly a change that gets pushed to the
source when validating fires. In other cases it was us 'cleaning' up the
data for presentation and forgetting to 'unclean' before the validating
event fired. You may want to look a Format an Parse events if you are doing
anything like this.


John Wynstra said:
No new rows are added.

The Issue_Id is set by the calling form. The Issue_ID is used as the
basis for retreiving the articles from the data source. Here is the
function from the data class which is called during form_load.

Public Shared Function GetArticles(ByVal issue_id As String) As DataSet

Dim sSQL = "Select article_id, title, page, doc_type,
summary,issue_id,url FROM Articles where issue_id = '" & issue_id & "'
Order by page ASC"
Dim conIXU As OleDbConnection = GetIXUConnection(CONN)
Dim daArticles As New OleDbDataAdapter(sSQL, conIXU)
Dim dsArticles As New DataSet()
daArticles.Fill(dsArticles, "ixu_articles")
conIXU.Close()
Return dsArticles
End Function

When I set the Article_ID(primary key for table) column to read only the
navigation will not move forward. When I set any of the other columns
to readonly, the app throws an "Error Number:5 occured. Description:
Column'TITLE' is read only. Source:System.Data" message whenever I try
to move forward. So somehow, the simple act of moving to the next row
is causing a change in the data.

Still baffled.
John:

Ok, if it fails then we're dealing with a clean set. Is there a new row or
anything like that?

I've seen this once when I tried using a bindingcontext and set a combobox's
databindings and used the bindigncontext for it, but also set the datasource
and valuemember.

What is me.Issue_Id? Use a search and find everything hwere you are
referencing the datatable...make sure nothing behind the scenes or something
that you meant to comment out is it.

Another thing, one by one Set the ReadOnly property of the underlying
datacolumn (not the textbox) to true --- if something is changing the value
outside of the ui, readonly on the textbox won't catch it, then you'll spot
it this way. If every column is readonly, then nothing will be able to be
edited, so do it one at a time. Also, don't undo it each time.. First time
set Column[0].ReadOnly = True next set 0 & 1, next 0,1,2. This is
redundant, but it will help make things certain that it's not a calculation
or something.
William,

Thanks for taking the time to reply. The Debug.Assert fails.

I don't have any events associated with these textbox controls.

If I navigate forward once, and do nothing else, it shows just one row
modified, and if I move forward twice and do nothing, it shows two rows
modified, etc. I do not have anything else going on that I have been
able to put my finger on.

I am using ms oledb provider to connect to an Oracle database on the
backend. I have wondered if there is some type conversion that is
happening to the data as it is presented in the textbox which actually
changes the data. The fields in the oracle table are mostly varchar,
but two are integer fields.

By the way, I have also tested setting the "read only" property to true
for each of the text boxes displaying the dataset, and I still get
haschanges(DataRowState.Modified) for each row that I navigate through.
I'm baffled.


William Ryan eMVP wrote:

John:

Before you make a move anywhere...insert a
Debug.Assert(Me.dsarticlelist.HasChanges) and see if it fails.

I can't tell from here but do you have any events in your textbox
controls

that chnage the data or anything? If you just navigate forward once, do
nothing else, does it show just one row modified for instance? Is there
anything else going on?


I’m running into a problem with a dataset where the columns are bound to
text boxes on a form. By merely navigating through the records using a
bindingmanagerbase, the rowstate for each row that I navigate through
changes to modified even though I have not edited the data. What would
cause this? I have included the relevant CODE.


'FORM DATASET DECLARED
Friend dsarticlelist As New DataSet()
Friend issue_id As String
Dim bmgrid As BindingManagerBase


'LOAD THE FORM, FILL DATASET, BIND TO CONTROLS
Private Sub frmArticle_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

loadarticles(Me.issue_id)
Me.BindArticleDataSettofields()
bmgrid = BindingContext(Me.dsarticlelist, "ixu_articles")
'Me.loadauthorsubjects(txtArticle_id.Text)
End Sub

Private Sub loadarticles(ByVal i_id As String)
dsarticlelist = ixudata.GetArticles(i_id)
End Sub

'SET ISSUE_ID THAT IS USED TO GET ARTICLES
Public Sub SetIssue_ID(ByVal i_id As String)
Me.issue_id = i_id
End Sub

'BIND DATASET TO CONTROLS
Private Sub BindArticleDataSettofields()
Me.txtTitle.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.title"))
Me.txtSummary.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.summary"))
Me.txtDoc_Type.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.doc_type"))
Me.txtPage.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.page"))
Me.txturl.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.url"))
Me.txtIssue_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.issue_id"))
Me.txtArticle_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.article_id"))
End Sub

'MOVE FORWARD THROUGH DATASET
Private Sub MoveNext()
Me.bmgrid.Position += 1
End Sub

'MOVE BACKWARD THROUGH DATASET
Private Sub MovePrevious()
Me.bmgrid.Position -= 1
End Sub

'EVENT THAT TRIGGERS MOVE FORWARD
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click
Me.MoveNext()
End Sub
'EVENT THAT TRIGGERS MOVE BACKWARD
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnPrevious.Click
Me.MovePrevious()
End Sub

'DISPLAYs ROWS THAT HAVE BEEN MODIFIED IN A DATAGRID
Private Sub btnSave_issue_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSave_issue.Click

Try
If Me.dsarticlelist.HasChanges Then
Dim myds_u_articles As New DataSet()
myds_u_articles =
Me.dsarticlelist.GetChanges(DataRowState.Modified)
Me.dgdchanges.DataSource = myds_u_articles

'If (ixudata.UpdateArticlesinDB(myds_u_articles)) Then
'Me.dsarticlelist.AcceptChanges()
'Else
' Me.dsarticlelist.RejectChanges()
'End If
End If
Catch
UnhandledExceptionHandler()

End Try
End Sub
 
W

William Ryan eMVP

Ok, something is trying to write to it, and succeeding when the read only
isn't on. (BTW, get rid of that dynamic sql and use parameters...many bad
things come from dynamic sql-trust me on this). I think you posted, but do
all the values in the row change or just a few, if just a few which ones.
What do they change to?
John Wynstra said:
No new rows are added.

The Issue_Id is set by the calling form. The Issue_ID is used as the
basis for retreiving the articles from the data source. Here is the
function from the data class which is called during form_load.

Public Shared Function GetArticles(ByVal issue_id As String) As DataSet

Dim sSQL = "Select article_id, title, page, doc_type,
summary,issue_id,url FROM Articles where issue_id = '" & issue_id & "'
Order by page ASC"
Dim conIXU As OleDbConnection = GetIXUConnection(CONN)
Dim daArticles As New OleDbDataAdapter(sSQL, conIXU)
Dim dsArticles As New DataSet()
daArticles.Fill(dsArticles, "ixu_articles")
conIXU.Close()
Return dsArticles
End Function

When I set the Article_ID(primary key for table) column to read only the
navigation will not move forward. When I set any of the other columns
to readonly, the app throws an "Error Number:5 occured. Description:
Column'TITLE' is read only. Source:System.Data" message whenever I try
to move forward. So somehow, the simple act of moving to the next row
is causing a change in the data.

Still baffled.
John:

Ok, if it fails then we're dealing with a clean set. Is there a new row or
anything like that?

I've seen this once when I tried using a bindingcontext and set a combobox's
databindings and used the bindigncontext for it, but also set the datasource
and valuemember.

What is me.Issue_Id? Use a search and find everything hwere you are
referencing the datatable...make sure nothing behind the scenes or something
that you meant to comment out is it.

Another thing, one by one Set the ReadOnly property of the underlying
datacolumn (not the textbox) to true --- if something is changing the value
outside of the ui, readonly on the textbox won't catch it, then you'll spot
it this way. If every column is readonly, then nothing will be able to be
edited, so do it one at a time. Also, don't undo it each time.. First time
set Column[0].ReadOnly = True next set 0 & 1, next 0,1,2. This is
redundant, but it will help make things certain that it's not a calculation
or something.
William,

Thanks for taking the time to reply. The Debug.Assert fails.

I don't have any events associated with these textbox controls.

If I navigate forward once, and do nothing else, it shows just one row
modified, and if I move forward twice and do nothing, it shows two rows
modified, etc. I do not have anything else going on that I have been
able to put my finger on.

I am using ms oledb provider to connect to an Oracle database on the
backend. I have wondered if there is some type conversion that is
happening to the data as it is presented in the textbox which actually
changes the data. The fields in the oracle table are mostly varchar,
but two are integer fields.

By the way, I have also tested setting the "read only" property to true
for each of the text boxes displaying the dataset, and I still get
haschanges(DataRowState.Modified) for each row that I navigate through.
I'm baffled.


William Ryan eMVP wrote:

John:

Before you make a move anywhere...insert a
Debug.Assert(Me.dsarticlelist.HasChanges) and see if it fails.

I can't tell from here but do you have any events in your textbox
controls

that chnage the data or anything? If you just navigate forward once, do
nothing else, does it show just one row modified for instance? Is there
anything else going on?


I’m running into a problem with a dataset where the columns are bound to
text boxes on a form. By merely navigating through the records using a
bindingmanagerbase, the rowstate for each row that I navigate through
changes to modified even though I have not edited the data. What would
cause this? I have included the relevant CODE.


'FORM DATASET DECLARED
Friend dsarticlelist As New DataSet()
Friend issue_id As String
Dim bmgrid As BindingManagerBase


'LOAD THE FORM, FILL DATASET, BIND TO CONTROLS
Private Sub frmArticle_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

loadarticles(Me.issue_id)
Me.BindArticleDataSettofields()
bmgrid = BindingContext(Me.dsarticlelist, "ixu_articles")
'Me.loadauthorsubjects(txtArticle_id.Text)
End Sub

Private Sub loadarticles(ByVal i_id As String)
dsarticlelist = ixudata.GetArticles(i_id)
End Sub

'SET ISSUE_ID THAT IS USED TO GET ARTICLES
Public Sub SetIssue_ID(ByVal i_id As String)
Me.issue_id = i_id
End Sub

'BIND DATASET TO CONTROLS
Private Sub BindArticleDataSettofields()
Me.txtTitle.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.title"))
Me.txtSummary.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.summary"))
Me.txtDoc_Type.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.doc_type"))
Me.txtPage.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.page"))
Me.txturl.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.url"))
Me.txtIssue_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.issue_id"))
Me.txtArticle_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.article_id"))
End Sub

'MOVE FORWARD THROUGH DATASET
Private Sub MoveNext()
Me.bmgrid.Position += 1
End Sub

'MOVE BACKWARD THROUGH DATASET
Private Sub MovePrevious()
Me.bmgrid.Position -= 1
End Sub

'EVENT THAT TRIGGERS MOVE FORWARD
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click
Me.MoveNext()
End Sub
'EVENT THAT TRIGGERS MOVE BACKWARD
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnPrevious.Click
Me.MovePrevious()
End Sub

'DISPLAYs ROWS THAT HAVE BEEN MODIFIED IN A DATAGRID
Private Sub btnSave_issue_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSave_issue.Click

Try
If Me.dsarticlelist.HasChanges Then
Dim myds_u_articles As New DataSet()
myds_u_articles =
Me.dsarticlelist.GetChanges(DataRowState.Modified)
Me.dgdchanges.DataSource = myds_u_articles

'If (ixudata.UpdateArticlesinDB(myds_u_articles)) Then
'Me.dsarticlelist.AcceptChanges()
'Else
' Me.dsarticlelist.RejectChanges()
'End If
End If
Catch
UnhandledExceptionHandler()

End Try
End Sub
 
G

Greg

This method will become your best fried:

Private Shared Function DataReallyIsDirty(ByVal dt As DataTable) As Boolean
Dim result As Boolean = False

For Each drw As DataRow In dt.Rows
If drw.RowState = DataRowState.Modified Then
Dim curr, orig As String
For Each col As DataColumn In dt.Columns
Try
If col.ColumnName.Trim <>
"names_timestamp_column" AndAlso col.ColumnName.Trim <> "formtitle" Then
curr = drw(col,
DataRowVersion.Current).ToString().Trim()
orig = drw(col,
DataRowVersion.Original).ToString().Trim()
If (Not curr.Equals(orig) OrElse _
curr <> orig OrElse _
String.CompareOrdinal(curr, orig) <> 0))
Then
-------------------> stick a debug.writeline here to see which column is
the problem
result = True
End If
End If
End Try
Next
End If
Next

Return result
End Function

End Function ' DataReallyIsDirty
William Ryan eMVP said:
Ok, something is trying to write to it, and succeeding when the read only
isn't on. (BTW, get rid of that dynamic sql and use parameters...many bad
things come from dynamic sql-trust me on this). I think you posted, but do
all the values in the row change or just a few, if just a few which ones.
What do they change to?
John Wynstra said:
No new rows are added.

The Issue_Id is set by the calling form. The Issue_ID is used as the
basis for retreiving the articles from the data source. Here is the
function from the data class which is called during form_load.

Public Shared Function GetArticles(ByVal issue_id As String) As DataSet

Dim sSQL = "Select article_id, title, page, doc_type,
summary,issue_id,url FROM Articles where issue_id = '" & issue_id & "'
Order by page ASC"
Dim conIXU As OleDbConnection = GetIXUConnection(CONN)
Dim daArticles As New OleDbDataAdapter(sSQL, conIXU)
Dim dsArticles As New DataSet()
daArticles.Fill(dsArticles, "ixu_articles")
conIXU.Close()
Return dsArticles
End Function

When I set the Article_ID(primary key for table) column to read only the
navigation will not move forward. When I set any of the other columns
to readonly, the app throws an "Error Number:5 occured. Description:
Column'TITLE' is read only. Source:System.Data" message whenever I try
to move forward. So somehow, the simple act of moving to the next row
is causing a change in the data.

Still baffled.
row
to
be
edited, so do it one at a time. Also, don't undo it each time.. First time
set Column[0].ReadOnly = True next set 0 & 1, next 0,1,2. This is
redundant, but it will help make things certain that it's not a calculation
or something.

William,

Thanks for taking the time to reply. The Debug.Assert fails.

I don't have any events associated with these textbox controls.

If I navigate forward once, and do nothing else, it shows just one row
modified, and if I move forward twice and do nothing, it shows two rows
modified, etc. I do not have anything else going on that I have been
able to put my finger on.

I am using ms oledb provider to connect to an Oracle database on the
backend. I have wondered if there is some type conversion that is
happening to the data as it is presented in the textbox which actually
changes the data. The fields in the oracle table are mostly varchar,
but two are integer fields.

By the way, I have also tested setting the "read only" property to true
for each of the text boxes displaying the dataset, and I still get
haschanges(DataRowState.Modified) for each row that I navigate through.
I'm baffled.


William Ryan eMVP wrote:

John:

Before you make a move anywhere...insert a
Debug.Assert(Me.dsarticlelist.HasChanges) and see if it fails.

I can't tell from here but do you have any events in your textbox

controls

that chnage the data or anything? If you just navigate forward once, do
nothing else, does it show just one row modified for instance? Is there
anything else going on?


I'm running into a problem with a dataset where the columns are
bound
using
 
J

John Wynstra

OK. I tried Greg's Method "DataREallyIsDirty" and it seems to indicate
that the data hasn't actually changed. As a test, I changed some data,
and "DataReallyIsDirty" indicated which column had the changes, however
when just navigating through the data, "DataReallyIsDirty" does not
indicate that any columns have actually changed. A quick inspection of
the data also shows no changes after navigating, but a simple call to this

Dim myds_u_articles As New DataSet()
myds_u_articles = Me.dsarticlelist.GetChanges(DataRowState.Modified)

returns every row that has been navigated through. Even more baffled.
Not April 1st today is it?? Where is the hidden camera?!?!?
This method will become your best fried:

Private Shared Function DataReallyIsDirty(ByVal dt As DataTable) As Boolean
Dim result As Boolean = False

For Each drw As DataRow In dt.Rows
If drw.RowState = DataRowState.Modified Then
Dim curr, orig As String
For Each col As DataColumn In dt.Columns
Try
If col.ColumnName.Trim <>
"names_timestamp_column" AndAlso col.ColumnName.Trim <> "formtitle" Then
curr = drw(col,
DataRowVersion.Current).ToString().Trim()
orig = drw(col,
DataRowVersion.Original).ToString().Trim()
If (Not curr.Equals(orig) OrElse _
curr <> orig OrElse _
String.CompareOrdinal(curr, orig) <> 0))
Then
-------------------> stick a debug.writeline here to see which column is
the problem
result = True
End If
End If
End Try
Next
End If
Next

Return result
End Function

End Function ' DataReallyIsDirty
Ok, something is trying to write to it, and succeeding when the read only
isn't on. (BTW, get rid of that dynamic sql and use parameters...many bad
things come from dynamic sql-trust me on this). I think you posted, but
do

all the values in the row change or just a few, if just a few which ones.
What do they change to?
No new rows are added.

The Issue_Id is set by the calling form. The Issue_ID is used as the
basis for retreiving the articles from the data source. Here is the
function from the data class which is called during form_load.

Public Shared Function GetArticles(ByVal issue_id As String) As DataSet

Dim sSQL = "Select article_id, title, page, doc_type,
summary,issue_id,url FROM Articles where issue_id = '" & issue_id & "'
Order by page ASC"
Dim conIXU As OleDbConnection = GetIXUConnection(CONN)
Dim daArticles As New OleDbDataAdapter(sSQL, conIXU)
Dim dsArticles As New DataSet()
daArticles.Fill(dsArticles, "ixu_articles")
conIXU.Close()
Return dsArticles
End Function

When I set the Article_ID(primary key for table) column to read only the
navigation will not move forward. When I set any of the other columns
to readonly, the app throws an "Error Number:5 occured. Description:
Column'TITLE' is read only. Source:System.Data" message whenever I try
to move forward. So somehow, the simple act of moving to the next row
is causing a change in the data.

Still baffled.

William Ryan eMVP wrote:


John:

Ok, if it fails then we're dealing with a clean set. Is there a new
row
or

anything like that?

I've seen this once when I tried using a bindingcontext and set a
combobox's

databindings and used the bindigncontext for it, but also set the
datasource

and valuemember.

What is me.Issue_Id? Use a search and find everything hwere you are
referencing the datatable...make sure nothing behind the scenes or
something

that you meant to comment out is it.

Another thing, one by one Set the ReadOnly property of the underlying
datacolumn (not the textbox) to true --- if something is changing the
value

outside of the ui, readonly on the textbox won't catch it, then you'll
spot

it this way. If every column is readonly, then nothing will be able
to
be

edited, so do it one at a time. Also, don't undo it each time.. First
time

set Column[0].ReadOnly = True next set 0 & 1, next 0,1,2. This is
redundant, but it will help make things certain that it's not a
calculation

or something.


William,

Thanks for taking the time to reply. The Debug.Assert fails.

I don't have any events associated with these textbox controls.

If I navigate forward once, and do nothing else, it shows just one row
modified, and if I move forward twice and do nothing, it shows two
rows
modified, etc. I do not have anything else going on that I have been
able to put my finger on.

I am using ms oledb provider to connect to an Oracle database on the
backend. I have wondered if there is some type conversion that is
happening to the data as it is presented in the textbox which actually
changes the data. The fields in the oracle table are mostly varchar,
but two are integer fields.

By the way, I have also tested setting the "read only" property to
true
for each of the text boxes displaying the dataset, and I still get
haschanges(DataRowState.Modified) for each row that I navigate
through.
I'm baffled.


William Ryan eMVP wrote:


John:

Before you make a move anywhere...insert a
Debug.Assert(Me.dsarticlelist.HasChanges) and see if it fails.

I can't tell from here but do you have any events in your textbox

controls


that chnage the data or anything? If you just navigate forward once,
do

nothing else, does it show just one row modified for instance? Is
there

anything else going on?



I'm running into a problem with a dataset where the columns are
bound
to

text boxes on a form. By merely navigating through the records
using
a

bindingmanagerbase, the rowstate for each row that I navigate
through
changes to modified even though I have not edited the data. What
would

cause this? I have included the relevant CODE.


'FORM DATASET DECLARED
Friend dsarticlelist As New DataSet()
Friend issue_id As String
Dim bmgrid As BindingManagerBase


'LOAD THE FORM, FILL DATASET, BIND TO CONTROLS
Private Sub frmArticle_Load(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles MyBase.Load

loadarticles(Me.issue_id)
Me.BindArticleDataSettofields()
bmgrid = BindingContext(Me.dsarticlelist, "ixu_articles")
'Me.loadauthorsubjects(txtArticle_id.Text)
End Sub

Private Sub loadarticles(ByVal i_id As String)
dsarticlelist = ixudata.GetArticles(i_id)
End Sub

'SET ISSUE_ID THAT IS USED TO GET ARTICLES
Public Sub SetIssue_ID(ByVal i_id As String)
Me.issue_id = i_id
End Sub

'BIND DATASET TO CONTROLS
Private Sub BindArticleDataSettofields()
Me.txtTitle.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.title"))
Me.txtSummary.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.summary"))
Me.txtDoc_Type.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.doc_type"))
Me.txtPage.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.page"))
Me.txturl.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.url"))
Me.txtIssue_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.issue_id"))
Me.txtArticle_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.article_id"))
End Sub

'MOVE FORWARD THROUGH DATASET
Private Sub MoveNext()
Me.bmgrid.Position += 1
End Sub

'MOVE BACKWARD THROUGH DATASET
Private Sub MovePrevious()
Me.bmgrid.Position -= 1
End Sub

'EVENT THAT TRIGGERS MOVE FORWARD
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e
As

System.EventArgs) Handles btnNext.Click
Me.MoveNext()
End Sub
'EVENT THAT TRIGGERS MOVE BACKWARD
Private Sub btnPrevious_Click(ByVal sender As System.Object,
ByVal
e As System.EventArgs) Handles btnPrevious.Click
Me.MovePrevious()
End Sub

'DISPLAYs ROWS THAT HAVE BEEN MODIFIED IN A DATAGRID
Private Sub btnSave_issue_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSave_issue.Click

Try
If Me.dsarticlelist.HasChanges Then
Dim myds_u_articles As New DataSet()
myds_u_articles =
Me.dsarticlelist.GetChanges(DataRowState.Modified)
Me.dgdchanges.DataSource = myds_u_articles

'If (ixudata.UpdateArticlesinDB(myds_u_articles))
Then
'Me.dsarticlelist.AcceptChanges()
'Else
' Me.dsarticlelist.RejectChanges()
'End If
End If
Catch
UnhandledExceptionHandler()

End Try
End Sub
 
W

William Ryan eMVP

but at the same time HasChanges is true?
John Wynstra said:
OK. I tried Greg's Method "DataREallyIsDirty" and it seems to indicate
that the data hasn't actually changed. As a test, I changed some data,
and "DataReallyIsDirty" indicated which column had the changes, however
when just navigating through the data, "DataReallyIsDirty" does not
indicate that any columns have actually changed. A quick inspection of
the data also shows no changes after navigating, but a simple call to this

Dim myds_u_articles As New DataSet()
myds_u_articles = Me.dsarticlelist.GetChanges(DataRowState.Modified)

returns every row that has been navigated through. Even more baffled.
Not April 1st today is it?? Where is the hidden camera?!?!?
This method will become your best fried:

Private Shared Function DataReallyIsDirty(ByVal dt As DataTable) As Boolean
Dim result As Boolean = False

For Each drw As DataRow In dt.Rows
If drw.RowState = DataRowState.Modified Then
Dim curr, orig As String
For Each col As DataColumn In dt.Columns
Try
If col.ColumnName.Trim <>
"names_timestamp_column" AndAlso col.ColumnName.Trim <> "formtitle" Then
curr = drw(col,
DataRowVersion.Current).ToString().Trim()
orig = drw(col,
DataRowVersion.Original).ToString().Trim()
If (Not curr.Equals(orig) OrElse _
curr <> orig OrElse _
String.CompareOrdinal(curr, orig) <> 0))
Then
-------------------> stick a debug.writeline here to see which column is
the problem
result = True
End If
End If
End Try
Next
End If
Next

Return result
End Function

End Function ' DataReallyIsDirty
Ok, something is trying to write to it, and succeeding when the read only
isn't on. (BTW, get rid of that dynamic sql and use parameters...many bad
things come from dynamic sql-trust me on this). I think you posted, but
do

all the values in the row change or just a few, if just a few which ones.
What do they change to?

No new rows are added.

The Issue_Id is set by the calling form. The Issue_ID is used as the
basis for retreiving the articles from the data source. Here is the
function from the data class which is called during form_load.

Public Shared Function GetArticles(ByVal issue_id As String) As DataSet

Dim sSQL = "Select article_id, title, page, doc_type,
summary,issue_id,url FROM Articles where issue_id = '" & issue_id & "'
Order by page ASC"
Dim conIXU As OleDbConnection = GetIXUConnection(CONN)
Dim daArticles As New OleDbDataAdapter(sSQL, conIXU)
Dim dsArticles As New DataSet()
daArticles.Fill(dsArticles, "ixu_articles")
conIXU.Close()
Return dsArticles
End Function

When I set the Article_ID(primary key for table) column to read only the
navigation will not move forward. When I set any of the other columns
to readonly, the app throws an "Error Number:5 occured. Description:
Column'TITLE' is read only. Source:System.Data" message whenever I try
to move forward. So somehow, the simple act of moving to the next row
is causing a change in the data.

Still baffled.

William Ryan eMVP wrote:


John:

Ok, if it fails then we're dealing with a clean set. Is there a new
row

or

anything like that?

I've seen this once when I tried using a bindingcontext and set a

combobox's

databindings and used the bindigncontext for it, but also set the

datasource

and valuemember.

What is me.Issue_Id? Use a search and find everything hwere you are
referencing the datatable...make sure nothing behind the scenes or

something

that you meant to comment out is it.

Another thing, one by one Set the ReadOnly property of the underlying
datacolumn (not the textbox) to true --- if something is changing the

value

outside of the ui, readonly on the textbox won't catch it, then you'll

spot

it this way. If every column is readonly, then nothing will be able
to

be

edited, so do it one at a time. Also, don't undo it each time.. First

time

set Column[0].ReadOnly = True next set 0 & 1, next 0,1,2. This is
redundant, but it will help make things certain that it's not a

calculation

or something.


William,

Thanks for taking the time to reply. The Debug.Assert fails.

I don't have any events associated with these textbox controls.

If I navigate forward once, and do nothing else, it shows just one row
modified, and if I move forward twice and do nothing, it shows two
rows

modified, etc. I do not have anything else going on that I have been
able to put my finger on.

I am using ms oledb provider to connect to an Oracle database on the
backend. I have wondered if there is some type conversion that is
happening to the data as it is presented in the textbox which actually
changes the data. The fields in the oracle table are mostly varchar,
but two are integer fields.

By the way, I have also tested setting the "read only" property to
true

for each of the text boxes displaying the dataset, and I still get
haschanges(DataRowState.Modified) for each row that I navigate
through.

I'm baffled.


William Ryan eMVP wrote:


John:

Before you make a move anywhere...insert a
Debug.Assert(Me.dsarticlelist.HasChanges) and see if it fails.

I can't tell from here but do you have any events in your textbox

controls


that chnage the data or anything? If you just navigate forward once,

do

nothing else, does it show just one row modified for instance? Is

there

anything else going on?



I'm running into a problem with a dataset where the columns are
bound

to

text boxes on a form. By merely navigating through the records
using

a

bindingmanagerbase, the rowstate for each row that I navigate
through

changes to modified even though I have not edited the data. What

would

cause this? I have included the relevant CODE.


'FORM DATASET DECLARED
Friend dsarticlelist As New DataSet()
Friend issue_id As String
Dim bmgrid As BindingManagerBase


'LOAD THE FORM, FILL DATASET, BIND TO CONTROLS
Private Sub frmArticle_Load(ByVal sender As System.Object, ByVal e
As

System.EventArgs) Handles MyBase.Load

loadarticles(Me.issue_id)
Me.BindArticleDataSettofields()
bmgrid = BindingContext(Me.dsarticlelist, "ixu_articles")
'Me.loadauthorsubjects(txtArticle_id.Text)
End Sub

Private Sub loadarticles(ByVal i_id As String)
dsarticlelist = ixudata.GetArticles(i_id)
End Sub

'SET ISSUE_ID THAT IS USED TO GET ARTICLES
Public Sub SetIssue_ID(ByVal i_id As String)
Me.issue_id = i_id
End Sub

'BIND DATASET TO CONTROLS
Private Sub BindArticleDataSettofields()
Me.txtTitle.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.title"))
Me.txtSummary.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.summary"))
Me.txtDoc_Type.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.doc_type"))
Me.txtPage.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.page"))
Me.txturl.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.url"))
Me.txtIssue_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.issue_id"))
Me.txtArticle_id.DataBindings.Add(New Binding("text", _
Me.dsarticlelist, "ixu_articles.article_id"))
End Sub

'MOVE FORWARD THROUGH DATASET
Private Sub MoveNext()
Me.bmgrid.Position += 1
End Sub

'MOVE BACKWARD THROUGH DATASET
Private Sub MovePrevious()
Me.bmgrid.Position -= 1
End Sub

'EVENT THAT TRIGGERS MOVE FORWARD
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e

As

System.EventArgs) Handles btnNext.Click
Me.MoveNext()
End Sub
'EVENT THAT TRIGGERS MOVE BACKWARD
Private Sub btnPrevious_Click(ByVal sender As System.Object,
ByVal

e As System.EventArgs) Handles btnPrevious.Click
Me.MovePrevious()
End Sub

'DISPLAYs ROWS THAT HAVE BEEN MODIFIED IN A DATAGRID
Private Sub btnSave_issue_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSave_issue.Click

Try
If Me.dsarticlelist.HasChanges Then
Dim myds_u_articles As New DataSet()
myds_u_articles =
Me.dsarticlelist.GetChanges(DataRowState.Modified)
Me.dgdchanges.DataSource = myds_u_articles

'If (ixudata.UpdateArticlesinDB(myds_u_articles))
Then

'Me.dsarticlelist.AcceptChanges()
'Else
' Me.dsarticlelist.RejectChanges()
'End If
End If
Catch
UnhandledExceptionHandler()

End Try
End Sub
 
G

Greg

If you are changing a char(5) that was storing ' ' to ' ' on your
client, this will get flagged as a change. If I recall, my method does not
find this.
 
J

John Wynstra

I'm convinced that some type of conversion(nothing that I have set up)
is happening to the data as it appears in the text boxes. I ended up
binding the columns one at a time to the form and then testing the form
with only one column bound. HasChanges happended every time and only to
rows that were navigated through. I have spent way to much time on this
one problem. It would be much better if the text box left the data
alone by default unless the the control actually had focus and the data
was changed.

Some fields have (Null) in them before the navigation and they must be
being changed to "". Unfortunately, even when all fields contain data,
I still get HasChanges.
 
G

Greg

"Some fields have (Null) in them before the navigation and they must be
being changed to "". Unfortunately, even when all fields contain data,
I still get HasChanges.
"

there you go, you are changing something if I understand this statement.
May want to look at setting DefaultValues on the fields in question.
 
G

Guest

The problem is with the parse of the data.

Dim item_price_binding As New Binding("text", dsData.Tables("item_partner"), "item_price")
AddHandler item_price_binding.Format, AddressOf MoneyToString
AddHandler item_price_binding.Parse, AddressOf StringToMoney
item_price.DataBindings.Add(item_price_binding)

when i remove the handler for de parse, i don't have this problem.
the data is changed in a function before i save it to the database.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top