duplicate records being recorded

  • Thread starter Thread starter Martin Williams
  • Start date Start date
M

Martin Williams

Still working out a few bugs in a survey program I'm writing. The way I
have it configured is as each survey is completed, the dataset is updated.
When the program is closed, the database itself is updated. However, when I
check the database table, there are some answers that are duplicated two and
three times.

Here are some snippets...

//This sub is called on the last page of the survey when the "Finish" button
is clicked.
Sub GatherAndUpdateAnswers()
//there is some code before this that gathers all the answers and assigns
them to variables
dim newrecord as datarow = mainform.dssurveydata1.survey_data.newrow
newrecord(0) = QuestionOneAnswer
newrecord(2) = QuestionTwoAnswer
//repeats like this until twelve

mainform.dssurveydata1.survey_data.rows.add(newrecord)

end sub

Sub UpdateData()
dim pdsInsertedRows as system.data.dataset
pdsInsertedRows = mainform.dssurvey_data1.getchanges(datarowstate.added)
mainform.oledbdataadapter1.update(pdsInsertedRows)
end sub

Private Sub Form1_Closing(...)
Call UpdateData()
end sub

When the "Finish" button is clicked on the last form,
GatherAndUpdateAnswers() is called.
 
Another problem discovered...

Some of the text fields in the database that require some longer answers are
cutting off the data. I have the appropriate fields set to "Memo", which is
not supposed to have a default length, but it's still happening. Any ideas?
 
Martin,

You are aware of the fact that the getchanges create a copy dataset of the
changes.
The original dataset will in this case not be affected by the build in
acceptchanges from the dataadapter.

Cor
 
So, do I change my UpdateAnswers sub to just AcceptChanges from the dataset?
I thought the dataset was a disconnected view of the database itself, but
the program updates the database just from adding rows to the dataset. If
it works, it works, I'm just trying to get a handle on it.
 
Martin,

The acceptchanges set all the rowstate to done, what is a function as well
from the dataadapter, however you do that on the copy dataset getchanges.

So you can try to set that after the update.

As sample
\\\
if ds.haschanges then
ds.update(ds.getchanges)
ds.acceptchanges
end if
///
I hope this helps

Cor
 

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

Back
Top