473,408 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Discarding rows in dataset.

Hi all,

Would someone be able to tell me the most 'graceful' way of removing
unwanted rows from a dataset based on a condition prior to update? OR,
resetting the rows all to unchanged after they are initally added to the
recordset.

I create a dataset, which begins empty after the initial .Fill.

Then I create several rows with some default information, leaving one
critical piece of information value as 0;

dr = ds.Tables("mytable").NewRow()
With dr
.Item("basicdata1") = myvalue1
.Item("basicdata2") = myvalue2
.Item("criticaldata") = 0
.Item("created") = Now()
End With
ds.Tables("mytable").Rows.Add(dr)

Then, my update does something like;

da.Update(ds, "mytable")

All pretty basic stuff.... but what I would like is to ONLY insert new rows
into the database that have a "criticaldata" value <> 0 and discard the
rest. I could use the GetChanges method if I knew how to mark the rows as
'unchanged' immediately after creation - but don't know how.

Any help would be greatly appreciated.
Thanks,

Graham
Nov 20 '05 #1
12 1971
YOu can use GetChanges and just get the rows with RowState or added. Then
call update on the GetChanges table - then acceptChanges on the original
--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/...ity/newsgroups
"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:tH*********************@news20.bellglobal.com ...
Hi all,

Would someone be able to tell me the most 'graceful' way of removing
unwanted rows from a dataset based on a condition prior to update? OR,
resetting the rows all to unchanged after they are initally added to the
recordset.

I create a dataset, which begins empty after the initial .Fill.

Then I create several rows with some default information, leaving one
critical piece of information value as 0;

dr = ds.Tables("mytable").NewRow()
With dr
.Item("basicdata1") = myvalue1
.Item("basicdata2") = myvalue2
.Item("criticaldata") = 0
.Item("created") = Now()
End With
ds.Tables("mytable").Rows.Add(dr)

Then, my update does something like;

da.Update(ds, "mytable")

All pretty basic stuff.... but what I would like is to ONLY insert new rows into the database that have a "criticaldata" value <> 0 and discard the
rest. I could use the GetChanges method if I knew how to mark the rows as
'unchanged' immediately after creation - but don't know how.

Any help would be greatly appreciated.
Thanks,

Graham

Nov 20 '05 #2
I guess row.AcceptChanges will do.

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:tH*********************@news20.bellglobal.com ...
Hi all,

Would someone be able to tell me the most 'graceful' way of removing
unwanted rows from a dataset based on a condition prior to update? OR,
resetting the rows all to unchanged after they are initally added to the
recordset.

I create a dataset, which begins empty after the initial .Fill.

Then I create several rows with some default information, leaving one
critical piece of information value as 0;

dr = ds.Tables("mytable").NewRow()
With dr
.Item("basicdata1") = myvalue1
.Item("basicdata2") = myvalue2
.Item("criticaldata") = 0
.Item("created") = Now()
End With
ds.Tables("mytable").Rows.Add(dr)

Then, my update does something like;

da.Update(ds, "mytable")

All pretty basic stuff.... but what I would like is to ONLY insert new rows into the database that have a "criticaldata" value <> 0 and discard the
rest. I could use the GetChanges method if I knew how to mark the rows as
'unchanged' immediately after creation - but don't know how.

Any help would be greatly appreciated.
Thanks,

Graham

Nov 20 '05 #3
Graham,
In addition to GetChanges with the DataRowState you can use
DataTable.Select.

I would recommend DataTable.Select as you are returned references to the
rows in the existing DataSet, where as GetChanges will return a new DataSet
(with new rows).

David Sceppa explains the difference between GetChanges & Select when you
intend on updating the database in his book "Microsoft ADO.NET - Core
Reference" from MS
Press.

If you are doing a lot with ADO.NET I strongly recommend Sceppa's book,
which is a good tutorial on ADO.NET as well as a good desk reference once
you know ADO.NET.

Hope this helps
Jay
"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:tH*********************@news20.bellglobal.com ...
Hi all,

Would someone be able to tell me the most 'graceful' way of removing
unwanted rows from a dataset based on a condition prior to update? OR,
resetting the rows all to unchanged after they are initally added to the
recordset.

I create a dataset, which begins empty after the initial .Fill.

Then I create several rows with some default information, leaving one
critical piece of information value as 0;

dr = ds.Tables("mytable").NewRow()
With dr
.Item("basicdata1") = myvalue1
.Item("basicdata2") = myvalue2
.Item("criticaldata") = 0
.Item("created") = Now()
End With
ds.Tables("mytable").Rows.Add(dr)

Then, my update does something like;

da.Update(ds, "mytable")

All pretty basic stuff.... but what I would like is to ONLY insert new rows into the database that have a "criticaldata" value <> 0 and discard the
rest. I could use the GetChanges method if I knew how to mark the rows as
'unchanged' immediately after creation - but don't know how.

Any help would be greatly appreciated.
Thanks,

Graham

Nov 20 '05 #4
I don't think I made myself very clear in my original post - either that or
I am reading the response wrongly....

I have an empty dataset.
In code, I add say 3 rows - "row a", "row b" and "row c" with say a single
value which I set to 0 (zero).

I am led to believe that at this point, these rows will all be marked as
"added".

The user - through the interface may or may not change the value of these
rows to say, 1.

Now, if I perform an update on the dataset I ONLY want the rows that have
been changed to a value of 1.

As far as I understand, the GetChanges method isn't going to help me,
because the rowstate on all of the rows will be 'added' and therefore any
'change' to a value will be ignored, as it already has an 'added' state.

Is this making sense?

Thanks,
Graham

"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
YOu can use GetChanges and just get the rows with RowState or added. Then
call update on the GetChanges table - then acceptChanges on the original
--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/...ity/newsgroups
"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:tH*********************@news20.bellglobal.com ...
Hi all,

Would someone be able to tell me the most 'graceful' way of removing
unwanted rows from a dataset based on a condition prior to update? OR,
resetting the rows all to unchanged after they are initally added to the
recordset.

I create a dataset, which begins empty after the initial .Fill.

Then I create several rows with some default information, leaving one
critical piece of information value as 0;

dr = ds.Tables("mytable").NewRow()
With dr
.Item("basicdata1") = myvalue1
.Item("basicdata2") = myvalue2
.Item("criticaldata") = 0
.Item("created") = Now()
End With
ds.Tables("mytable").Rows.Add(dr)

Then, my update does something like;

da.Update(ds, "mytable")

All pretty basic stuff.... but what I would like is to ONLY insert new

rows
into the database that have a "criticaldata" value <> 0 and discard the
rest. I could use the GetChanges method if I knew how to mark the rows as 'unchanged' immediately after creation - but don't know how.

Any help would be greatly appreciated.
Thanks,

Graham


Nov 20 '05 #5
Graham,
I am led to believe that at this point, these rows will all be marked as
"added". Correct, they will be marked as Added, you can call AcceptChanges on the
dataset & they will no longer be marked as Added.

Thus allowing you to call GetChanges to get the row that the user changed to
a 1.

If you want to look for rows without 0s, you could use DataTable.Select to
return the rows without 0s, then pass this array of rows to your
DataAdapter.

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:vr*********************@news20.bellglobal.com ... I don't think I made myself very clear in my original post - either that or I am reading the response wrongly....

I have an empty dataset.
In code, I add say 3 rows - "row a", "row b" and "row c" with say a single
value which I set to 0 (zero).

I am led to believe that at this point, these rows will all be marked as
"added".

The user - through the interface may or may not change the value of these
rows to say, 1.

Now, if I perform an update on the dataset I ONLY want the rows that have
been changed to a value of 1.

As far as I understand, the GetChanges method isn't going to help me,
because the rowstate on all of the rows will be 'added' and therefore any
'change' to a value will be ignored, as it already has an 'added' state.

Is this making sense?

Thanks,
Graham

"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
YOu can use GetChanges and just get the rows with RowState or added. Then
call update on the GetChanges table - then acceptChanges on the original
--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/...ity/newsgroups
"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:tH*********************@news20.bellglobal.com ...
Hi all,

Would someone be able to tell me the most 'graceful' way of removing
unwanted rows from a dataset based on a condition prior to update? OR,
resetting the rows all to unchanged after they are initally added to the recordset.

I create a dataset, which begins empty after the initial .Fill.

Then I create several rows with some default information, leaving one
critical piece of information value as 0;

dr = ds.Tables("mytable").NewRow()
With dr
.Item("basicdata1") = myvalue1
.Item("basicdata2") = myvalue2
.Item("criticaldata") = 0
.Item("created") = Now()
End With
ds.Tables("mytable").Rows.Add(dr)

Then, my update does something like;

da.Update(ds, "mytable")

All pretty basic stuff.... but what I would like is to ONLY insert new rows
into the database that have a "criticaldata" value <> 0 and discard the rest. I could use the GetChanges method if I knew how to mark the

rows as 'unchanged' immediately after creation - but don't know how.

Any help would be greatly appreciated.
Thanks,

Graham



Nov 20 '05 #6
Thanks Jay,

I tried the former method, as it appears to be a more graceful answer - but
am a little confused. I call the AcceptChanges method once I have created my
new rows.

Then, after modifying one of the rows, I am doing something like this;

mynewdataset = myoriginaldataset.GetChanges() ' I also tried
GetChanges(Datarowstate.Modified)..
da.Update(mynewdataset, "mytable") ' Also tried .Update(myoriginalset,
"mytable") ...

Now I get the error;

"An unhandled exception of type 'System.Data.DBConcurrencyException'
occurred in system.data.dll
Additional information: Concurrency violation: the UpdateCommand affected 0
records."

Am I doing something wrong? - Should I be using a different method of
update?

If I can't do the update using this method, you mention the
DataTable.Select - I can use this - but am unsure on how you would process
the array of rows against the dataadaptor... I'll go looking for this, but
if you have a moment to explain I'd very much appreciate it....
Thanks again,
Graham


"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ek**************@tk2msftngp13.phx.gbl...
Graham,
I am led to believe that at this point, these rows will all be marked as
"added". Correct, they will be marked as Added, you can call AcceptChanges on the
dataset & they will no longer be marked as Added.

Thus allowing you to call GetChanges to get the row that the user changed

to a 1.

If you want to look for rows without 0s, you could use DataTable.Select to
return the rows without 0s, then pass this array of rows to your
DataAdapter.

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:vr*********************@news20.bellglobal.com ...
I don't think I made myself very clear in my original post - either that

or
I am reading the response wrongly....

I have an empty dataset.
In code, I add say 3 rows - "row a", "row b" and "row c" with say a single
value which I set to 0 (zero).

I am led to believe that at this point, these rows will all be marked as
"added".

The user - through the interface may or may not change the value of these rows to say, 1.

Now, if I perform an update on the dataset I ONLY want the rows that have been changed to a value of 1.

As far as I understand, the GetChanges method isn't going to help me,
because the rowstate on all of the rows will be 'added' and therefore any 'change' to a value will be ignored, as it already has an 'added' state.

Is this making sense?

Thanks,
Graham

"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
YOu can use GetChanges and just get the rows with RowState or added.

Then call update on the GetChanges table - then acceptChanges on the original

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/...ity/newsgroups
"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:tH*********************@news20.bellglobal.com ...
> Hi all,
>
> Would someone be able to tell me the most 'graceful' way of removing
> unwanted rows from a dataset based on a condition prior to update? OR, > resetting the rows all to unchanged after they are initally added to the > recordset.
>
> I create a dataset, which begins empty after the initial .Fill.
>
> Then I create several rows with some default information, leaving one > critical piece of information value as 0;
>
> dr = ds.Tables("mytable").NewRow()
> With dr
> .Item("basicdata1") = myvalue1
> .Item("basicdata2") = myvalue2
> .Item("criticaldata") = 0
> .Item("created") = Now()
> End With
> ds.Tables("mytable").Rows.Add(dr)
>
> Then, my update does something like;
>
> da.Update(ds, "mytable")
>
> All pretty basic stuff.... but what I would like is to ONLY insert new rows
> into the database that have a "criticaldata" value <> 0 and discard the > rest. I could use the GetChanges method if I knew how to mark the

rows
as
> 'unchanged' immediately after creation - but don't know how.
>
> Any help would be greatly appreciated.
> Thanks,
>
> Graham
>
>



Nov 20 '05 #7
Graham,
Appearences can be conceiving ;-)

What are you calling AcceptChanges on?

Are you calling it before or after you change the zeros to a one?

Can you post an actual sample of what you are attempting?

I don't have a sample, however you should be able to:
- create your dataset
- add the rows with zeros
- dataset.acceptchanges
- allow user to change zeros to one
- getchanges or datatable.select
- dataadapter.update

Reading the help on DBConcurrencyException, it sounds like you have a bad
update statement.
There is a overload on DataAdapter.Update that accepts an array of DataRows
(from the DataTable.Select for example).

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:FW*********************@news20.bellglobal.com ...
Thanks Jay,

I tried the former method, as it appears to be a more graceful answer - but am a little confused. I call the AcceptChanges method once I have created my new rows.

Then, after modifying one of the rows, I am doing something like this;

mynewdataset = myoriginaldataset.GetChanges() ' I also tried
GetChanges(Datarowstate.Modified)..
da.Update(mynewdataset, "mytable") ' Also tried .Update(myoriginalset,
"mytable") ...

Now I get the error;

"An unhandled exception of type 'System.Data.DBConcurrencyException'
occurred in system.data.dll
Additional information: Concurrency violation: the UpdateCommand affected 0 records."

Am I doing something wrong? - Should I be using a different method of
update?

If I can't do the update using this method, you mention the
DataTable.Select - I can use this - but am unsure on how you would process
the array of rows against the dataadaptor... I'll go looking for this, but
if you have a moment to explain I'd very much appreciate it....
Thanks again,
Graham


"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ek**************@tk2msftngp13.phx.gbl...
Graham,
I am led to believe that at this point, these rows will all be marked as "added". Correct, they will be marked as Added, you can call AcceptChanges on the
dataset & they will no longer be marked as Added.

Thus allowing you to call GetChanges to get the row that the user changed to
a 1.

If you want to look for rows without 0s, you could use DataTable.Select to return the rows without 0s, then pass this array of rows to your
DataAdapter.

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:vr*********************@news20.bellglobal.com ...
I don't think I made myself very clear in my original post - either that
or
I am reading the response wrongly....

I have an empty dataset.
In code, I add say 3 rows - "row a", "row b" and "row c" with say a single value which I set to 0 (zero).

I am led to believe that at this point, these rows will all be marked
as "added".

The user - through the interface may or may not change the value of

these rows to say, 1.

Now, if I perform an update on the dataset I ONLY want the rows that have been changed to a value of 1.

As far as I understand, the GetChanges method isn't going to help me,
because the rowstate on all of the rows will be 'added' and therefore any 'change' to a value will be ignored, as it already has an 'added' state.
Is this making sense?

Thanks,
Graham

"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
> YOu can use GetChanges and just get the rows with RowState or added.

Then
> call update on the GetChanges table - then acceptChanges on the original >
>
> --
> W.G. Ryan MVP Windows - Embedded
>
> Have an opinion on the effectiveness of Microsoft Embedded newsgroups? > Let Microsoft know!
> https://www.windowsembeddedeval.com/...ity/newsgroups
> "Graham Blandford" <gr**************@sympatico.ca> wrote in message
> news:tH*********************@news20.bellglobal.com ...
> > Hi all,
> >
> > Would someone be able to tell me the most 'graceful' way of removing > > unwanted rows from a dataset based on a condition prior to update? OR, > > resetting the rows all to unchanged after they are initally added
to the
> > recordset.
> >
> > I create a dataset, which begins empty after the initial .Fill.
> >
> > Then I create several rows with some default information, leaving one > > critical piece of information value as 0;
> >
> > dr = ds.Tables("mytable").NewRow()
> > With dr
> > .Item("basicdata1") = myvalue1
> > .Item("basicdata2") = myvalue2
> > .Item("criticaldata") = 0
> > .Item("created") = Now()
> > End With
> > ds.Tables("mytable").Rows.Add(dr)
> >
> > Then, my update does something like;
> >
> > da.Update(ds, "mytable")
> >
> > All pretty basic stuff.... but what I would like is to ONLY insert new > rows
> > into the database that have a "criticaldata" value <> 0 and

discard the
> > rest. I could use the GetChanges method if I knew how to mark the

rows
as
> > 'unchanged' immediately after creation - but don't know how.
> >
> > Any help would be greatly appreciated.
> > Thanks,
> >
> > Graham
> >
> >
>
>



Nov 20 '05 #8
Hi Jay,

Still no luck - I get the concurrency violation whether I overload the using
the .Select OR the GetChanges method.
The update statement looks fine, and indeed works if I do a straight forward
update without trying to filter out the zero-valued records.

Here's the code - inline with your requests.

Thanks for helping out.
Graham
- create your dataset Dataset is defined in the IDE along with the adaptor.
- add the rows with zeros
' Performed within a couple of nested loops;
drLinkMAN_crop_operations =
dsLinkMAN_crop_operations_1.Tables("crop_operation s").NewRow()
With drLinkMAN_crop_operations
.Item("summit_gdcid") = summit_gdcid
.Item("summit_farm_id") = drLinkMAN_field_trans.Item("summit_farm_id")
.Item("summit_field_id") = summit_field_id
.Item("year") = int_current_year
.Item("farm_id") = drLinkMAN_field_trans.Item("farm_id")
.Item("field_id") = drLinkMAN_field_trans.Item("field_id")
.Item("section_id") = drLinkMAN_field_trans.Item("section_id")
.Item("crop_id") = 0
.Item("created") = Now()

dsLinkMAN_crop_operations_1.Tables("crop_operation s").Rows.Add(drLinkMAN_cro
p_operations)
End With
- dataset.acceptchanges ' After the loop(s).
dsLinkMAN_crop_operations_1.AcceptChanges()
- allow user to change zeros to one Done via the interface - works - data is correct if I don't try to
remove the zero-valued rows.
- getchanges or datatable.select
- dataadapter.update
Dim dsMyChanges As New DataSet
dsMyChanges = dsLinkMAN_crop_operations_1.GetChanges(DataRowStat e.Modified)
If dsMyChanges.HasChanges Then
Dim intx As Int16
daLinkMAN_crop_operations.Update(dsMyChanges) '<---------------------
HERE IS WHERE I GET THE VIOLATION ERROR
If dsMyChanges.HasErrors Then
Dim e As String = ""
End If
End If

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl... Graham,
Appearences can be conceiving ;-)

What are you calling AcceptChanges on?

Are you calling it before or after you change the zeros to a one?

Can you post an actual sample of what you are attempting?

I don't have a sample, however you should be able to:
- create your dataset
- add the rows with zeros
- dataset.acceptchanges
- allow user to change zeros to one
- getchanges or datatable.select
- dataadapter.update

Reading the help on DBConcurrencyException, it sounds like you have a bad
update statement.
There is a overload on DataAdapter.Update that accepts an array of DataRows (from the DataTable.Select for example).

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:FW*********************@news20.bellglobal.com ...
Thanks Jay,

I tried the former method, as it appears to be a more graceful answer - but
am a little confused. I call the AcceptChanges method once I have created my
new rows.

Then, after modifying one of the rows, I am doing something like this;

mynewdataset = myoriginaldataset.GetChanges() ' I also tried
GetChanges(Datarowstate.Modified)..
da.Update(mynewdataset, "mytable") ' Also tried .Update(myoriginalset,
"mytable") ...

Now I get the error;

"An unhandled exception of type 'System.Data.DBConcurrencyException'
occurred in system.data.dll
Additional information: Concurrency violation: the UpdateCommand affected
0
records."

Am I doing something wrong? - Should I be using a different method of
update?

If I can't do the update using this method, you mention the
DataTable.Select - I can use this - but am unsure on how you would
process the array of rows against the dataadaptor... I'll go looking for this, but if you have a moment to explain I'd very much appreciate it....
Thanks again,
Graham


"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:ek**************@tk2msftngp13.phx.gbl...
Graham,
> I am led to believe that at this point, these rows will all be marked as > "added".
Correct, they will be marked as Added, you can call AcceptChanges on
the dataset & they will no longer be marked as Added.

Thus allowing you to call GetChanges to get the row that the user changed
to
a 1.

If you want to look for rows without 0s, you could use DataTable.Select
to return the rows without 0s, then pass this array of rows to your
DataAdapter.

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:vr*********************@news20.bellglobal.com ...
> I don't think I made myself very clear in my original post - either that or
> I am reading the response wrongly....
>
> I have an empty dataset.
> In code, I add say 3 rows - "row a", "row b" and "row c" with say a single
> value which I set to 0 (zero).
>
> I am led to believe that at this point, these rows will all be
marked as > "added".
>
> The user - through the interface may or may not change the value of these
> rows to say, 1.
>
> Now, if I perform an update on the dataset I ONLY want the rows that

have
> been changed to a value of 1.
>
> As far as I understand, the GetChanges method isn't going to help
me, > because the rowstate on all of the rows will be 'added' and therefore any
> 'change' to a value will be ignored, as it already has an 'added' state. >
> Is this making sense?
>
> Thanks,
> Graham
>
>
>
> "William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
> news:uU**************@tk2msftngp13.phx.gbl...
> > YOu can use GetChanges and just get the rows with RowState or
added. Then
> > call update on the GetChanges table - then acceptChanges on the

original
> >
> >
> > --
> > W.G. Ryan MVP Windows - Embedded
> >
> > Have an opinion on the effectiveness of Microsoft Embedded

newsgroups? > > Let Microsoft know!
> > https://www.windowsembeddedeval.com/...ity/newsgroups
> > "Graham Blandford" <gr**************@sympatico.ca> wrote in message > > news:tH*********************@news20.bellglobal.com ...
> > > Hi all,
> > >
> > > Would someone be able to tell me the most 'graceful' way of removing > > > unwanted rows from a dataset based on a condition prior to update? OR,
> > > resetting the rows all to unchanged after they are initally
added to the
> > > recordset.
> > >
> > > I create a dataset, which begins empty after the initial .Fill.
> > >
> > > Then I create several rows with some default information,
leaving
one
> > > critical piece of information value as 0;
> > >
> > > dr = ds.Tables("mytable").NewRow()
> > > With dr
> > > .Item("basicdata1") = myvalue1
> > > .Item("basicdata2") = myvalue2
> > > .Item("criticaldata") = 0
> > > .Item("created") = Now()
> > > End With
> > > ds.Tables("mytable").Rows.Add(dr)
> > >
> > > Then, my update does something like;
> > >
> > > da.Update(ds, "mytable")
> > >
> > > All pretty basic stuff.... but what I would like is to ONLY
insert new
> > rows
> > > into the database that have a "criticaldata" value <> 0 and

discard the
> > > rest. I could use the GetChanges method if I knew how to mark

the rows
> as
> > > 'unchanged' immediately after creation - but don't know how.
> > >
> > > Any help would be greatly appreciated.
> > > Thanks,
> > >
> > > Graham
> > >
> > >
> >
> >
>
>



Nov 20 '05 #9
Jay. I think I know the problem.

Would I be correct in thinking that when then I AcceptChanges on the
dataset, and then make a change, the row is marked as 'Modified' - and
subsequently calls the UpdateCommand, when in fact it needs to be calling
the InsertCommand??...

Cant believe it never clicked before... now I have to figure out how to
filter WITHOUT using the AcceptChanges. I guess I could use the
OnRowUpdating Handler - will that allow me to ignore a row if I mark it?

Thanks,
Graham

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:j6*********************@news20.bellglobal.com ...
Hi Jay,

Still no luck - I get the concurrency violation whether I overload the using the .Select OR the GetChanges method.
The update statement looks fine, and indeed works if I do a straight forward update without trying to filter out the zero-valued records.

Here's the code - inline with your requests.

Thanks for helping out.
Graham
- create your dataset Dataset is defined in the IDE along with the adaptor.
- add the rows with zeros


' Performed within a couple of nested loops;
drLinkMAN_crop_operations =
dsLinkMAN_crop_operations_1.Tables("crop_operation s").NewRow()
With drLinkMAN_crop_operations
.Item("summit_gdcid") = summit_gdcid
.Item("summit_farm_id") = drLinkMAN_field_trans.Item("summit_farm_id")
.Item("summit_field_id") = summit_field_id
.Item("year") = int_current_year
.Item("farm_id") = drLinkMAN_field_trans.Item("farm_id")
.Item("field_id") = drLinkMAN_field_trans.Item("field_id")
.Item("section_id") = drLinkMAN_field_trans.Item("section_id")
.Item("crop_id") = 0
.Item("created") = Now()

dsLinkMAN_crop_operations_1.Tables("crop_operation s").Rows.Add(drLinkMAN_cro p_operations)
End With
- dataset.acceptchanges ' After the loop(s).
dsLinkMAN_crop_operations_1.AcceptChanges()
- allow user to change zeros to one

Done via the interface - works - data is correct if I don't try to
remove the zero-valued rows.
- getchanges or datatable.select
- dataadapter.update


Dim dsMyChanges As New DataSet
dsMyChanges =

dsLinkMAN_crop_operations_1.GetChanges(DataRowStat e.Modified) If dsMyChanges.HasChanges Then
Dim intx As Int16
daLinkMAN_crop_operations.Update(dsMyChanges) '<---------------------
HERE IS WHERE I GET THE VIOLATION ERROR
If dsMyChanges.HasErrors Then
Dim e As String = ""
End If
End If

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl...
Graham,
Appearences can be conceiving ;-)

What are you calling AcceptChanges on?

Are you calling it before or after you change the zeros to a one?

Can you post an actual sample of what you are attempting?

I don't have a sample, however you should be able to:
- create your dataset
- add the rows with zeros
- dataset.acceptchanges
- allow user to change zeros to one
- getchanges or datatable.select
- dataadapter.update

Reading the help on DBConcurrencyException, it sounds like you have a bad
update statement.
There is a overload on DataAdapter.Update that accepts an array of

DataRows
(from the DataTable.Select for example).

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:FW*********************@news20.bellglobal.com ...
Thanks Jay,

I tried the former method, as it appears to be a more graceful answer -
but
am a little confused. I call the AcceptChanges method once I have created
my
new rows.

Then, after modifying one of the rows, I am doing something like this;

mynewdataset = myoriginaldataset.GetChanges() ' I also tried
GetChanges(Datarowstate.Modified)..
da.Update(mynewdataset, "mytable") ' Also tried .Update(myoriginalset,
"mytable") ...

Now I get the error;

"An unhandled exception of type 'System.Data.DBConcurrencyException'
occurred in system.data.dll
Additional information: Concurrency violation: the UpdateCommand

affected
0
records."

Am I doing something wrong? - Should I be using a different method of
update?

If I can't do the update using this method, you mention the
DataTable.Select - I can use this - but am unsure on how you would

process the array of rows against the dataadaptor... I'll go looking for this, but if you have a moment to explain I'd very much appreciate it....
Thanks again,
Graham


"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:ek**************@tk2msftngp13.phx.gbl...
> Graham,
> > I am led to believe that at this point, these rows will all be marked
as
> > "added".
> Correct, they will be marked as Added, you can call AcceptChanges on

the > dataset & they will no longer be marked as Added.
>
> Thus allowing you to call GetChanges to get the row that the user

changed
to
> a 1.
>
> If you want to look for rows without 0s, you could use DataTable.Select
to
> return the rows without 0s, then pass this array of rows to your
> DataAdapter.
>
> Hope this helps
> Jay
>
> "Graham Blandford" <gr**************@sympatico.ca> wrote in message
> news:vr*********************@news20.bellglobal.com ...
> > I don't think I made myself very clear in my original post -

either that
> or
> > I am reading the response wrongly....
> >
> > I have an empty dataset.
> > In code, I add say 3 rows - "row a", "row b" and "row c" with say

a single
> > value which I set to 0 (zero).
> >
> > I am led to believe that at this point, these rows will all be

marked
as
> > "added".
> >
> > The user - through the interface may or may not change the value of these
> > rows to say, 1.
> >
> > Now, if I perform an update on the dataset I ONLY want the rows that have
> > been changed to a value of 1.
> >
> > As far as I understand, the GetChanges method isn't going to help

me, > > because the rowstate on all of the rows will be 'added' and therefore any
> > 'change' to a value will be ignored, as it already has an 'added'

state.
> >
> > Is this making sense?
> >
> > Thanks,
> > Graham
> >
> >
> >
> > "William Ryan eMVP" <do********@comcast.nospam.net> wrote in message > > news:uU**************@tk2msftngp13.phx.gbl...
> > > YOu can use GetChanges and just get the rows with RowState or added. > Then
> > > call update on the GetChanges table - then acceptChanges on the
original
> > >
> > >
> > > --
> > > W.G. Ryan MVP Windows - Embedded
> > >
> > > Have an opinion on the effectiveness of Microsoft Embedded

newsgroups?
> > > Let Microsoft know!
> > > https://www.windowsembeddedeval.com/...ity/newsgroups
> > > "Graham Blandford" <gr**************@sympatico.ca> wrote in message > > > news:tH*********************@news20.bellglobal.com ...
> > > > Hi all,
> > > >
> > > > Would someone be able to tell me the most 'graceful' way of

removing
> > > > unwanted rows from a dataset based on a condition prior to update? OR,
> > > > resetting the rows all to unchanged after they are initally added
to
> the
> > > > recordset.
> > > >
> > > > I create a dataset, which begins empty after the initial ..Fill. > > > >
> > > > Then I create several rows with some default information,

leaving one
> > > > critical piece of information value as 0;
> > > >
> > > > dr = ds.Tables("mytable").NewRow()
> > > > With dr
> > > > .Item("basicdata1") = myvalue1
> > > > .Item("basicdata2") = myvalue2
> > > > .Item("criticaldata") = 0
> > > > .Item("created") = Now()
> > > > End With
> > > > ds.Tables("mytable").Rows.Add(dr)
> > > >
> > > > Then, my update does something like;
> > > >
> > > > da.Update(ds, "mytable")
> > > >
> > > > All pretty basic stuff.... but what I would like is to ONLY insert new
> > > rows
> > > > into the database that have a "criticaldata" value <> 0 and

discard
> the
> > > > rest. I could use the GetChanges method if I knew how to mark the > rows
> > as
> > > > 'unchanged' immediately after creation - but don't know how.
> > > >
> > > > Any help would be greatly appreciated.
> > > > Thanks,
> > > >
> > > > Graham
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #10
Hi Jay,

Figured out a fairly graceful solution.
Added the handler, and deal with it in the Onrowupdating method: -

Protected Shared Sub OnRowUpdating(ByVal sender As Object, ByVal args As
OleDbRowUpdatingEventArgs)

If args.StatementType = StatementType.Insert Then
If args.Command.Parameters("crop_id").Value = 0 Then
args.Status = UpdateStatus.SkipCurrentRow
End If
End If

End Sub

Works well!

Once again, thanks for all your help.
Graham

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:wt*********************@news20.bellglobal.com ...
Jay. I think I know the problem.

Would I be correct in thinking that when then I AcceptChanges on the
dataset, and then make a change, the row is marked as 'Modified' - and
subsequently calls the UpdateCommand, when in fact it needs to be calling
the InsertCommand??...

Cant believe it never clicked before... now I have to figure out how to
filter WITHOUT using the AcceptChanges. I guess I could use the
OnRowUpdating Handler - will that allow me to ignore a row if I mark it?

Thanks,
Graham

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:j6*********************@news20.bellglobal.com ...
Hi Jay,

Still no luck - I get the concurrency violation whether I overload the using
the .Select OR the GetChanges method.
The update statement looks fine, and indeed works if I do a straight

forward
update without trying to filter out the zero-valued records.

Here's the code - inline with your requests.

Thanks for helping out.
Graham
- create your dataset

Dataset is defined in the IDE along with the adaptor.
- add the rows with zeros


' Performed within a couple of nested loops;
drLinkMAN_crop_operations =
dsLinkMAN_crop_operations_1.Tables("crop_operation s").NewRow()
With drLinkMAN_crop_operations
.Item("summit_gdcid") = summit_gdcid
.Item("summit_farm_id") = drLinkMAN_field_trans.Item("summit_farm_id")
.Item("summit_field_id") = summit_field_id
.Item("year") = int_current_year
.Item("farm_id") = drLinkMAN_field_trans.Item("farm_id")
.Item("field_id") = drLinkMAN_field_trans.Item("field_id")
.Item("section_id") = drLinkMAN_field_trans.Item("section_id")
.Item("crop_id") = 0
.Item("created") = Now()

dsLinkMAN_crop_operations_1.Tables("crop_operation s").Rows.Add(drLinkMAN_cro
p_operations)
End With
- dataset.acceptchanges

' After the loop(s).
dsLinkMAN_crop_operations_1.AcceptChanges()
- allow user to change zeros to one

Done via the interface - works - data is correct if I don't try to
remove the zero-valued rows.
- getchanges or datatable.select
- dataadapter.update


Dim dsMyChanges As New DataSet
dsMyChanges =

dsLinkMAN_crop_operations_1.GetChanges(DataRowStat e.Modified)
If dsMyChanges.HasChanges Then
Dim intx As Int16
daLinkMAN_crop_operations.Update(dsMyChanges) '<--------------------- HERE IS WHERE I GET THE VIOLATION ERROR
If dsMyChanges.HasErrors Then
Dim e As String = ""
End If
End If

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:u%****************@TK2MSFTNGP09.phx.gbl...
Graham,
Appearences can be conceiving ;-)

What are you calling AcceptChanges on?

Are you calling it before or after you change the zeros to a one?

Can you post an actual sample of what you are attempting?

I don't have a sample, however you should be able to:
- create your dataset
- add the rows with zeros
- dataset.acceptchanges
- allow user to change zeros to one
- getchanges or datatable.select
- dataadapter.update

Reading the help on DBConcurrencyException, it sounds like you have a bad update statement.
There is a overload on DataAdapter.Update that accepts an array of

DataRows
(from the DataTable.Select for example).

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:FW*********************@news20.bellglobal.com ...
> Thanks Jay,
>
> I tried the former method, as it appears to be a more graceful answer - but
> am a little confused. I call the AcceptChanges method once I have

created
my
> new rows.
>
> Then, after modifying one of the rows, I am doing something like this; >
> mynewdataset = myoriginaldataset.GetChanges() ' I also tried
> GetChanges(Datarowstate.Modified)..
> da.Update(mynewdataset, "mytable") ' Also tried ..Update(myoriginalset, > "mytable") ...
>
> Now I get the error;
>
> "An unhandled exception of type 'System.Data.DBConcurrencyException'
> occurred in system.data.dll
> Additional information: Concurrency violation: the UpdateCommand

affected
0
> records."
>
> Am I doing something wrong? - Should I be using a different method of > update?
>
> If I can't do the update using this method, you mention the
> DataTable.Select - I can use this - but am unsure on how you would

process
> the array of rows against the dataadaptor... I'll go looking for this, but
> if you have a moment to explain I'd very much appreciate it....
>
>
> Thanks again,
> Graham
>
>
>
>
> "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in

message
> news:ek**************@tk2msftngp13.phx.gbl...
> > Graham,
> > > I am led to believe that at this point, these rows will all be

marked
as
> > > "added".
> > Correct, they will be marked as Added, you can call AcceptChanges
on
the
> > dataset & they will no longer be marked as Added.
> >
> > Thus allowing you to call GetChanges to get the row that the user
changed
> to
> > a 1.
> >
> > If you want to look for rows without 0s, you could use

DataTable.Select
to
> > return the rows without 0s, then pass this array of rows to your
> > DataAdapter.
> >
> > Hope this helps
> > Jay
> >
> > "Graham Blandford" <gr**************@sympatico.ca> wrote in
message > > news:vr*********************@news20.bellglobal.com ...
> > > I don't think I made myself very clear in my original post -

either that
> > or
> > > I am reading the response wrongly....
> > >
> > > I have an empty dataset.
> > > In code, I add say 3 rows - "row a", "row b" and "row c" with say a
> single
> > > value which I set to 0 (zero).
> > >
> > > I am led to believe that at this point, these rows will all be

marked
as
> > > "added".
> > >
> > > The user - through the interface may or may not change the value of > these
> > > rows to say, 1.
> > >
> > > Now, if I perform an update on the dataset I ONLY want the rows that > have
> > > been changed to a value of 1.
> > >
> > > As far as I understand, the GetChanges method isn't going to
help me,
> > > because the rowstate on all of the rows will be 'added' and

therefore
> any
> > > 'change' to a value will be ignored, as it already has an
'added' state.
> > >
> > > Is this making sense?
> > >
> > > Thanks,
> > > Graham
> > >
> > >
> > >
> > > "William Ryan eMVP" <do********@comcast.nospam.net> wrote in

message > > > news:uU**************@tk2msftngp13.phx.gbl...
> > > > YOu can use GetChanges and just get the rows with RowState or

added.
> > Then
> > > > call update on the GetChanges table - then acceptChanges on the > original
> > > >
> > > >
> > > > --
> > > > W.G. Ryan MVP Windows - Embedded
> > > >
> > > > Have an opinion on the effectiveness of Microsoft Embedded
newsgroups?
> > > > Let Microsoft know!
> > > > https://www.windowsembeddedeval.com/...ity/newsgroups
> > > > "Graham Blandford" <gr**************@sympatico.ca> wrote in

message
> > > > news:tH*********************@news20.bellglobal.com ...
> > > > > Hi all,
> > > > >
> > > > > Would someone be able to tell me the most 'graceful' way of
removing
> > > > > unwanted rows from a dataset based on a condition prior to

update?
> OR,
> > > > > resetting the rows all to unchanged after they are initally

added
to
> > the
> > > > > recordset.
> > > > >
> > > > > I create a dataset, which begins empty after the initial .Fill. > > > > >
> > > > > Then I create several rows with some default information,

leaving
> one
> > > > > critical piece of information value as 0;
> > > > >
> > > > > dr = ds.Tables("mytable").NewRow()
> > > > > With dr
> > > > > .Item("basicdata1") = myvalue1
> > > > > .Item("basicdata2") = myvalue2
> > > > > .Item("criticaldata") = 0
> > > > > .Item("created") = Now()
> > > > > End With
> > > > > ds.Tables("mytable").Rows.Add(dr)
> > > > >
> > > > > Then, my update does something like;
> > > > >
> > > > > da.Update(ds, "mytable")
> > > > >
> > > > > All pretty basic stuff.... but what I would like is to ONLY

insert
> new
> > > > rows
> > > > > into the database that have a "criticaldata" value <> 0 and
discard
> > the
> > > > > rest. I could use the GetChanges method if I knew how to

mark the
> > rows
> > > as
> > > > > 'unchanged' immediately after creation - but don't know how.
> > > > >
> > > > > Any help would be greatly appreciated.
> > > > > Thanks,
> > > > >
> > > > > Graham
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #11
Graham,
You are correct, if you AcceptChanges, all your "new" rows will now be
Modified & not Added, the Adapter will attempt to call the UpdateCommand
instead of the InsertCommand.

If due to the nature of your process all "Modified" rows are really inserts,
I probably would simply put the Insert Statement in the UpdateCommand also,
which might be "easier" then handling the RowUpdating event...

An alternative I used in a couple of other places is to have a single
"Update" stored procedure, that the SP itself decides if its an insert or
update. Both the UpdateCommand & InsertCommand of the DataAdapter would use
this same stored procedure...

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:wt*********************@news20.bellglobal.com ...
Jay. I think I know the problem.

Would I be correct in thinking that when then I AcceptChanges on the
dataset, and then make a change, the row is marked as 'Modified' - and
subsequently calls the UpdateCommand, when in fact it needs to be calling
the InsertCommand??...

Cant believe it never clicked before... now I have to figure out how to
filter WITHOUT using the AcceptChanges. I guess I could use the
OnRowUpdating Handler - will that allow me to ignore a row if I mark it?

Thanks,
Graham

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:j6*********************@news20.bellglobal.com ...
Hi Jay,

Still no luck - I get the concurrency violation whether I overload the using
the .Select OR the GetChanges method.
The update statement looks fine, and indeed works if I do a straight

forward
update without trying to filter out the zero-valued records.

Here's the code - inline with your requests.

Thanks for helping out.
Graham
- create your dataset

Dataset is defined in the IDE along with the adaptor.
- add the rows with zeros


' Performed within a couple of nested loops;
drLinkMAN_crop_operations =
dsLinkMAN_crop_operations_1.Tables("crop_operation s").NewRow()
With drLinkMAN_crop_operations
.Item("summit_gdcid") = summit_gdcid
.Item("summit_farm_id") = drLinkMAN_field_trans.Item("summit_farm_id")
.Item("summit_field_id") = summit_field_id
.Item("year") = int_current_year
.Item("farm_id") = drLinkMAN_field_trans.Item("farm_id")
.Item("field_id") = drLinkMAN_field_trans.Item("field_id")
.Item("section_id") = drLinkMAN_field_trans.Item("section_id")
.Item("crop_id") = 0
.Item("created") = Now()

dsLinkMAN_crop_operations_1.Tables("crop_operation s").Rows.Add(drLinkMAN_cro
p_operations)
End With
- dataset.acceptchanges

' After the loop(s).
dsLinkMAN_crop_operations_1.AcceptChanges()
- allow user to change zeros to one

Done via the interface - works - data is correct if I don't try to
remove the zero-valued rows.
- getchanges or datatable.select
- dataadapter.update


Dim dsMyChanges As New DataSet
dsMyChanges =

dsLinkMAN_crop_operations_1.GetChanges(DataRowStat e.Modified)
If dsMyChanges.HasChanges Then
Dim intx As Int16
daLinkMAN_crop_operations.Update(dsMyChanges) '<--------------------- HERE IS WHERE I GET THE VIOLATION ERROR
If dsMyChanges.HasErrors Then
Dim e As String = ""
End If
End If

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:u%****************@TK2MSFTNGP09.phx.gbl...
Graham,
Appearences can be conceiving ;-)

What are you calling AcceptChanges on?

Are you calling it before or after you change the zeros to a one?

Can you post an actual sample of what you are attempting?

I don't have a sample, however you should be able to:
- create your dataset
- add the rows with zeros
- dataset.acceptchanges
- allow user to change zeros to one
- getchanges or datatable.select
- dataadapter.update

Reading the help on DBConcurrencyException, it sounds like you have a bad update statement.
There is a overload on DataAdapter.Update that accepts an array of

DataRows
(from the DataTable.Select for example).

Hope this helps
Jay

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:FW*********************@news20.bellglobal.com ...
> Thanks Jay,
>
> I tried the former method, as it appears to be a more graceful answer - but
> am a little confused. I call the AcceptChanges method once I have

created
my
> new rows.
>
> Then, after modifying one of the rows, I am doing something like this; >
> mynewdataset = myoriginaldataset.GetChanges() ' I also tried
> GetChanges(Datarowstate.Modified)..
> da.Update(mynewdataset, "mytable") ' Also tried ..Update(myoriginalset, > "mytable") ...
>
> Now I get the error;
>
> "An unhandled exception of type 'System.Data.DBConcurrencyException'
> occurred in system.data.dll
> Additional information: Concurrency violation: the UpdateCommand

affected
0
> records."
>
> Am I doing something wrong? - Should I be using a different method of > update?
>
> If I can't do the update using this method, you mention the
> DataTable.Select - I can use this - but am unsure on how you would

process
> the array of rows against the dataadaptor... I'll go looking for this, but
> if you have a moment to explain I'd very much appreciate it....
>
>
> Thanks again,
> Graham
>
>
>
>
> "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in

message
> news:ek**************@tk2msftngp13.phx.gbl...
> > Graham,
> > > I am led to believe that at this point, these rows will all be

marked
as
> > > "added".
> > Correct, they will be marked as Added, you can call AcceptChanges
on
the
> > dataset & they will no longer be marked as Added.
> >
> > Thus allowing you to call GetChanges to get the row that the user
changed
> to
> > a 1.
> >
> > If you want to look for rows without 0s, you could use

DataTable.Select
to
> > return the rows without 0s, then pass this array of rows to your
> > DataAdapter.
> >
> > Hope this helps
> > Jay
> >
> > "Graham Blandford" <gr**************@sympatico.ca> wrote in
message > > news:vr*********************@news20.bellglobal.com ...
> > > I don't think I made myself very clear in my original post -

either that
> > or
> > > I am reading the response wrongly....
> > >
> > > I have an empty dataset.
> > > In code, I add say 3 rows - "row a", "row b" and "row c" with say a
> single
> > > value which I set to 0 (zero).
> > >
> > > I am led to believe that at this point, these rows will all be

marked
as
> > > "added".
> > >
> > > The user - through the interface may or may not change the value of > these
> > > rows to say, 1.
> > >
> > > Now, if I perform an update on the dataset I ONLY want the rows that > have
> > > been changed to a value of 1.
> > >
> > > As far as I understand, the GetChanges method isn't going to
help me,
> > > because the rowstate on all of the rows will be 'added' and

therefore
> any
> > > 'change' to a value will be ignored, as it already has an
'added' state.
> > >
> > > Is this making sense?
> > >
> > > Thanks,
> > > Graham
> > >
> > >
> > >
> > > "William Ryan eMVP" <do********@comcast.nospam.net> wrote in

message > > > news:uU**************@tk2msftngp13.phx.gbl...
> > > > YOu can use GetChanges and just get the rows with RowState or

added.
> > Then
> > > > call update on the GetChanges table - then acceptChanges on the > original
> > > >
> > > >
> > > > --
> > > > W.G. Ryan MVP Windows - Embedded
> > > >
> > > > Have an opinion on the effectiveness of Microsoft Embedded
newsgroups?
> > > > Let Microsoft know!
> > > > https://www.windowsembeddedeval.com/...ity/newsgroups
> > > > "Graham Blandford" <gr**************@sympatico.ca> wrote in

message
> > > > news:tH*********************@news20.bellglobal.com ...
> > > > > Hi all,
> > > > >
> > > > > Would someone be able to tell me the most 'graceful' way of
removing
> > > > > unwanted rows from a dataset based on a condition prior to

update?
> OR,
> > > > > resetting the rows all to unchanged after they are initally

added
to
> > the
> > > > > recordset.
> > > > >
> > > > > I create a dataset, which begins empty after the initial .Fill. > > > > >
> > > > > Then I create several rows with some default information,

leaving
> one
> > > > > critical piece of information value as 0;
> > > > >
> > > > > dr = ds.Tables("mytable").NewRow()
> > > > > With dr
> > > > > .Item("basicdata1") = myvalue1
> > > > > .Item("basicdata2") = myvalue2
> > > > > .Item("criticaldata") = 0
> > > > > .Item("created") = Now()
> > > > > End With
> > > > > ds.Tables("mytable").Rows.Add(dr)
> > > > >
> > > > > Then, my update does something like;
> > > > >
> > > > > da.Update(ds, "mytable")
> > > > >
> > > > > All pretty basic stuff.... but what I would like is to ONLY

insert
> new
> > > > rows
> > > > > into the database that have a "criticaldata" value <> 0 and
discard
> > the
> > > > > rest. I could use the GetChanges method if I knew how to

mark the
> > rows
> > > as
> > > > > 'unchanged' immediately after creation - but don't know how.
> > > > >
> > > > > Any help would be greatly appreciated.
> > > > > Thanks,
> > > > >
> > > > > Graham
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #12
Hi Graham,

In this part of the message you show exactly where the acceptchanges is for.
I have an empty dataset.
In code, I add say 3 rows - "row a", "row b" and "row c" with say a single
value which I set to 0 (zero).


Here you have to do the acceptchanges.

And than all changes after this are marked as updated.

I hope this helps?

Cor
Nov 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tome73 | last post by:
How can I easily add the rows of DataTable1 to the rows of DataTable2. Both queries are from the same table. I can always use the column names with myRow, but I was wishing for a shortcut. When I...
4
by: baylor | last post by:
i have a DataSet (TDS). It has 4 rows in it. i want to erase those. For the life of me i can't figure out how Option 1: foreach foreach (DataRow row in dataSet.MY_TABLE.Rows) { row.Delete(); }...
3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
4
by: RG | last post by:
Using VB.NET, How do I insert rows from a SQL Server table into an Access table with the same structure (and also the reverse, from Access to SQL)? I’m new to this, so here’s what I’ve...
2
by: muntyanu | last post by:
Hi all, I have problem when merging existing DataTable into new dataset. DataSet ds = new DataSet(); while ( done ) { // fill myCustomDataSet.MyTable with data ds.Merge(...
1
by: whitecrow | last post by:
Hi All, I have a DataGrid that is a visual representation of a DataSet. It was created like so: dataset = new DataSet(); adapter.Fill(dataset); dataGridTable.DataSource = dataset.Tables;...
0
by: andrewcw | last post by:
I take a DataSet - with datatable with NO records, add records like this, verify the number of rows But the DataSet reports it has no changes. What am I missing ??? Thanks !!! DataSet dsITA...
4
by: Andre | last post by:
I am ruinning this in the global.asa VIA Visual Studio VB .NET (framework 1.1) I have a access database with a table called tblCounters with a feild called Counters with on row of data in it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.