473,770 Members | 4,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("myta ble").NewRow()
With dr
.Item("basicdat a1") = myvalue1
.Item("basicdat a2") = myvalue2
.Item("critical data") = 0
.Item("created" ) = Now()
End With
ds.Tables("myta ble").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 "criticalda ta" 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 2006
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******** *************@n ews20.bellgloba l.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("myta ble").NewRow()
With dr
.Item("basicdat a1") = myvalue1
.Item("basicdat a2") = myvalue2
.Item("critical data") = 0
.Item("created" ) = Now()
End With
ds.Tables("myta ble").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 "criticalda ta" 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.AcceptChang es will do.

"Graham Blandford" <gr************ **@sympatico.ca > wrote in message
news:tH******** *************@n ews20.bellgloba l.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("myta ble").NewRow()
With dr
.Item("basicdat a1") = myvalue1
.Item("basicdat a2") = myvalue2
.Item("critical data") = 0
.Item("created" ) = Now()
End With
ds.Tables("myta ble").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 "criticalda ta" 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.Selec t.

I would recommend DataTable.Selec t 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******** *************@n ews20.bellgloba l.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("myta ble").NewRow()
With dr
.Item("basicdat a1") = myvalue1
.Item("basicdat a2") = myvalue2
.Item("critical data") = 0
.Item("created" ) = Now()
End With
ds.Tables("myta ble").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 "criticalda ta" 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********@com cast.nospam.net > wrote in message
news:uU******** ******@tk2msftn gp13.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******** *************@n ews20.bellgloba l.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("myta ble").NewRow()
With dr
.Item("basicdat a1") = myvalue1
.Item("basicdat a2") = myvalue2
.Item("critical data") = 0
.Item("created" ) = Now()
End With
ds.Tables("myta ble").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 "criticalda ta" 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.Selec t 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******** *************@n ews20.bellgloba l.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********@com cast.nospam.net > wrote in message
news:uU******** ******@tk2msftn gp13.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******** *************@n ews20.bellgloba l.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("myta ble").NewRow()
With dr
.Item("basicdat a1") = myvalue1
.Item("basicdat a2") = myvalue2
.Item("critical data") = 0
.Item("created" ) = Now()
End With
ds.Tables("myta ble").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 "criticalda ta" 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 = myoriginaldatas et.GetChanges() ' I also tried
GetChanges(Data rowstate.Modifi ed)..
da.Update(mynew dataset, "mytable") ' Also tried .Update(myorigi nalset,
"mytable") ...

Now I get the error;

"An unhandled exception of type 'System.Data.DB ConcurrencyExce ption'
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.Selec t - 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******** ******@tk2msftn gp13.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.Selec t 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******** *************@n ews20.bellgloba l.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********@com cast.nospam.net > wrote in message
news:uU******** ******@tk2msftn gp13.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******** *************@n ews20.bellgloba l.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("myta ble").NewRow()
> With dr
> .Item("basicdat a1") = myvalue1
> .Item("basicdat a2") = myvalue2
> .Item("critical data") = 0
> .Item("created" ) = Now()
> End With
> ds.Tables("myta ble").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 "criticalda ta" 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.acceptc hanges
- allow user to change zeros to one
- getchanges or datatable.selec t
- dataadapter.upd ate

Reading the help on DBConcurrencyEx ception, it sounds like you have a bad
update statement.
There is a overload on DataAdapter.Upd ate that accepts an array of DataRows
(from the DataTable.Selec t for example).

Hope this helps
Jay

"Graham Blandford" <gr************ **@sympatico.ca > wrote in message
news:FW******** *************@n ews20.bellgloba l.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 = myoriginaldatas et.GetChanges() ' I also tried
GetChanges(Data rowstate.Modifi ed)..
da.Update(mynew dataset, "mytable") ' Also tried .Update(myorigi nalset,
"mytable") ...

Now I get the error;

"An unhandled exception of type 'System.Data.DB ConcurrencyExce ption'
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.Selec t - 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******** ******@tk2msftn gp13.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.Selec t 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******** *************@n ews20.bellgloba l.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********@com cast.nospam.net > wrote in message
news:uU******** ******@tk2msftn gp13.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******** *************@n ews20.bellgloba l.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("myta ble").NewRow()
> > With dr
> > .Item("basicdat a1") = myvalue1
> > .Item("basicdat a2") = myvalue2
> > .Item("critical data") = 0
> > .Item("created" ) = Now()
> > End With
> > ds.Tables("myta ble").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 "criticalda ta" 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.Ta bles("crop_oper ations").NewRow ()
With drLinkMAN_crop_ operations
.Item("summit_g dcid") = summit_gdcid
.Item("summit_f arm_id") = drLinkMAN_field _trans.Item("su mmit_farm_id")
.Item("summit_f ield_id") = summit_field_id
.Item("year") = int_current_yea r
.Item("farm_id" ) = drLinkMAN_field _trans.Item("fa rm_id")
.Item("field_id ") = drLinkMAN_field _trans.Item("fi eld_id")
.Item("section_ id") = drLinkMAN_field _trans.Item("se ction_id")
.Item("crop_id" ) = 0
.Item("created" ) = Now()

dsLinkMAN_crop_ operations_1.Ta bles("crop_oper ations").Rows.A dd(drLinkMAN_cr o
p_operations)
End With
- dataset.acceptc hanges ' After the loop(s).
dsLinkMAN_crop_ operations_1.Ac ceptChanges()
- 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.selec t
- dataadapter.upd ate
Dim dsMyChanges As New DataSet
dsMyChanges = dsLinkMAN_crop_ operations_1.Ge tChanges(DataRo wState.Modified )
If dsMyChanges.Has Changes Then
Dim intx As Int16
daLinkMAN_crop_ operations.Upda te(dsMyChanges) '<---------------------
HERE IS WHERE I GET THE VIOLATION ERROR
If dsMyChanges.Has Errors Then
Dim e As String = ""
End If
End If

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:u%******** ********@TK2MSF TNGP09.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.acceptc hanges
- allow user to change zeros to one
- getchanges or datatable.selec t
- dataadapter.upd ate

Reading the help on DBConcurrencyEx ception, it sounds like you have a bad
update statement.
There is a overload on DataAdapter.Upd ate that accepts an array of DataRows (from the DataTable.Selec t for example).

Hope this helps
Jay

"Graham Blandford" <gr************ **@sympatico.ca > wrote in message
news:FW******** *************@n ews20.bellgloba l.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 = myoriginaldatas et.GetChanges() ' I also tried
GetChanges(Data rowstate.Modifi ed)..
da.Update(mynew dataset, "mytable") ' Also tried .Update(myorigi nalset,
"mytable") ...

Now I get the error;

"An unhandled exception of type 'System.Data.DB ConcurrencyExce ption'
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.Selec t - 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******** ******@tk2msftn gp13.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.Selec t
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******** *************@n ews20.bellgloba l.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********@com cast.nospam.net > wrote in message
> news:uU******** ******@tk2msftn gp13.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******** *************@n ews20.bellgloba l.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("myta ble").NewRow()
> > > With dr
> > > .Item("basicdat a1") = myvalue1
> > > .Item("basicdat a2") = myvalue2
> > > .Item("critical data") = 0
> > > .Item("created" ) = Now()
> > > End With
> > > ds.Tables("myta ble").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 "criticalda ta" 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******** *************@n ews20.bellgloba l.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.Ta bles("crop_oper ations").NewRow ()
With drLinkMAN_crop_ operations
.Item("summit_g dcid") = summit_gdcid
.Item("summit_f arm_id") = drLinkMAN_field _trans.Item("su mmit_farm_id")
.Item("summit_f ield_id") = summit_field_id
.Item("year") = int_current_yea r
.Item("farm_id" ) = drLinkMAN_field _trans.Item("fa rm_id")
.Item("field_id ") = drLinkMAN_field _trans.Item("fi eld_id")
.Item("section_ id") = drLinkMAN_field _trans.Item("se ction_id")
.Item("crop_id" ) = 0
.Item("created" ) = Now()

dsLinkMAN_crop_ operations_1.Ta bles("crop_oper ations").Rows.A dd(drLinkMAN_cr o p_operations)
End With
- dataset.acceptc hanges ' After the loop(s).
dsLinkMAN_crop_ operations_1.Ac ceptChanges()
- 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.selec t
- dataadapter.upd ate


Dim dsMyChanges As New DataSet
dsMyChanges =

dsLinkMAN_crop_ operations_1.Ge tChanges(DataRo wState.Modified ) If dsMyChanges.Has Changes Then
Dim intx As Int16
daLinkMAN_crop_ operations.Upda te(dsMyChanges) '<---------------------
HERE IS WHERE I GET THE VIOLATION ERROR
If dsMyChanges.Has Errors Then
Dim e As String = ""
End If
End If

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:u%******** ********@TK2MSF TNGP09.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.acceptc hanges
- allow user to change zeros to one
- getchanges or datatable.selec t
- dataadapter.upd ate

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

DataRows
(from the DataTable.Selec t for example).

Hope this helps
Jay

"Graham Blandford" <gr************ **@sympatico.ca > wrote in message
news:FW******** *************@n ews20.bellgloba l.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 = myoriginaldatas et.GetChanges() ' I also tried
GetChanges(Data rowstate.Modifi ed)..
da.Update(mynew dataset, "mytable") ' Also tried .Update(myorigi nalset,
"mytable") ...

Now I get the error;

"An unhandled exception of type 'System.Data.DB ConcurrencyExce ption'
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.Selec t - 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******** ******@tk2msftn gp13.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.Selec t
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******** *************@n ews20.bellgloba l.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********@com cast.nospam.net > wrote in message > > news:uU******** ******@tk2msftn gp13.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******** *************@n ews20.bellgloba l.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("myta ble").NewRow()
> > > > With dr
> > > > .Item("basicdat a1") = myvalue1
> > > > .Item("basicdat a2") = myvalue2
> > > > .Item("critical data") = 0
> > > > .Item("created" ) = Now()
> > > > End With
> > > > ds.Tables("myta ble").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 "criticalda ta" 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

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

Similar topics

3
2793
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 try this it doesn’t work. for (int i = 0; i < dataTable1.Rows.Count; i++) { myRow = dataTable2.NewRow(); myRow = dataTable1.Rows; dataTable2.Rows.Add(myRow);
4
10437
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(); } This doesn't work. It erases the first row and then throws the exception Someone Changed The Enumerator. No fun
3
2547
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 "Resource" with the following structure : Resource{,en,fr,es} Yes.. these are the only languages supported actually. A couple of rows in that table would look like this :
3
4885
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 the best method? Do you have a sample of how to do this?
4
8607
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 tried so far (unsuccessfully): 1. Fill Dataset ‘S’ from a SQL Data Adapter (many rows). I see it in a DataGrid. 2. Fill Dataset ‘A’ from an Access OLE DB Data Adapter (just a few rows). In a second DataGrid. 3. Merge dataset ‘S’...
2
2110
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( myCustomDataSet.MyTable, bPreserveChanges, MissingSchemaAction.Add ); ds.AcceptChanges(); // tried with and without this line
1
1715
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; dataGridTable.TableStyles.Clear(); DataGridTableStyle tableStyle = new DataGridTableStyle(); dataGridTable.TableStyles.Add(tableStyle);
0
1187
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 = new DataSet(); dsITA = JetLayer.getDataSet("Select * from ITA", ita); // return a DataSet if (dsITA.Tables.Count > 0) {
4
3215
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 with a number. When I run the following code Imports System.Data Imports System.Data.OleDb Sub Session_Start......
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.