I have a data table that is connected to a database table with a data
adapter in the 'standard' manner.
However I want to be able to remove selected rows from the data table (i.e.
no longer include them in the set that is displayed to the user) but I don't
want to delete the corresponding row from the database.
I've tried using the .Rows.Remove() method but an exception is thrown to say
I don't have a 'delete' command in the data adapter (which I don't of
course).
Because of the way the 'user interface' works, I can't build up an SQL
string that represents the current set of records (the user can "add to" and
"remove from" the current set of records - there is no underlying SQL
statement that represents the totality of the users additions and removals)
so I can't just clear the table and re-fill it.
Is there a way to do this?
Thanks
Susan 7 6598
Susan,
Can you show us the piece of code that you use to remove, because in my idea
are you using the right approach. The remove should not affect any
dataadapter, it just completely removes a datarow from a datatable (as long
as it is not a parent row in a relation).
Cor
"Susan Mackay" <ma******@hotma il.comschreef in bericht
news:C1******** ************@ho tmail.com...
>I have a data table that is connected to a database table with a data
adapter in the 'standard' manner.
However I want to be able to remove selected rows from the data table
(i.e.
no longer include them in the set that is displayed to the user) but I
don't
want to delete the corresponding row from the database.
I've tried using the .Rows.Remove() method but an exception is thrown to
say
I don't have a 'delete' command in the data adapter (which I don't of
course).
Because of the way the 'user interface' works, I can't build up an SQL
string that represents the current set of records (the user can "add to"
and
"remove from" the current set of records - there is no underlying SQL
statement that represents the totality of the users additions and
removals)
so I can't just clear the table and re-fill it.
Is there a way to do this?
Thanks
Susan
Cor,
The relevant part is:
(Filterstring is a StringBuilder instance containing the row selection
statement, JobDataTable is the datatable in question)
DataRow[] TargetRows = JobDataTable.Se lect( FilterString.To String());
foreach( DataRow TargetRow in TargetRows)
{ JobDataTable.Ro ws.Remove( TargetRow); }
You may have already answered the question: the JobDataTable is the parent
of two relationships with other tables in the DataSet - JobAttributes and
JobContacts. Each is set up by code such as the following:
(DatabaseDS is the dataset that holds all of the tables)
DatabaseDS.Rela tions.Add("Jobs Attributes",
DatabaseDS.Tabl es["Jobs"].Columns["InternalJo bID"],
DatabaseDS.Tabl es["JobAttribu tes"].Columns["InternalJo bID"]);
The 'child' tables may or may not contain any records that relate to a
parent record.
I have a BindingSource instance that links a DataGridView with the data
table. The BindingSource has a CurrentChanged event on it, and the event
code updates the database if anything has changed (it then goes on to load
the child tables if they do not already have the appropriate records for the
new parent record - this stops [in some cases] hundreds of records being
read that will never be displayed/used). It is during the database update
that the exception is triggered.
The only other thing that might be relevant is that the parent table
(JobsDataTable) has a computed column:
JobDataTable.Co lumns.Add("MaxJ obStatus", typeof(int),
"iif(Count(Chil d(JobsContacts) .JobStatus)=0,J obStatus,Max(Ch ild(JobsContact s
).JobStatus))") ;
Thanks for the help - it is much appreciated
Susan
On 12/9/06 14:07, in article eJ************* @TK2MSFTNGP06.p hx.gbl, "Cor
Ligthert [MVP]" <no************ @planet.nlwrote :
Susan,
Can you show us the piece of code that you use to remove, because in my idea
are you using the right approach. The remove should not affect any
dataadapter, it just completely removes a datarow from a datatable (as long
as it is not a parent row in a relation).
Cor
"Susan Mackay" <ma******@hotma il.comschreef in bericht
news:C1******** ************@ho tmail.com...
>I have a data table that is connected to a database table with a data adapter in the 'standard' manner.
However I want to be able to remove selected rows from the data table (i.e. no longer include them in the set that is displayed to the user) but I don't want to delete the corresponding row from the database.
I've tried using the .Rows.Remove() method but an exception is thrown to say I don't have a 'delete' command in the data adapter (which I don't of course).
Because of the way the 'user interface' works, I can't build up an SQL string that represents the current set of records (the user can "add to" and "remove from" the current set of records - there is no underlying SQL statement that represents the totality of the users additions and removals) so I can't just clear the table and re-fill it.
Is there a way to do this?
Thanks
Susan
Susan,
First the last part, the update is only affecting those columns that are in
the SQL transaction code of that.
(Stored procedure or commandText).
However are you sure that that DataRow Array TargetRows is filled.
I become suspicious seeing that FilterString.To String(), the Select string
is not the most fine one to make.
Cor
"Susan Mackay" <ma******@hotma il.comschreef in bericht
news:C1******** ************@ho tmail.com...
Cor,
The relevant part is:
(Filterstring is a StringBuilder instance containing the row selection
statement, JobDataTable is the datatable in question)
DataRow[] TargetRows = JobDataTable.Se lect( FilterString.To String());
foreach( DataRow TargetRow in TargetRows)
{ JobDataTable.Ro ws.Remove( TargetRow); }
You may have already answered the question: the JobDataTable is the parent
of two relationships with other tables in the DataSet - JobAttributes and
JobContacts. Each is set up by code such as the following:
(DatabaseDS is the dataset that holds all of the tables)
DatabaseDS.Rela tions.Add("Jobs Attributes",
DatabaseDS.Tabl es["Jobs"].Columns["InternalJo bID"],
DatabaseDS.Tabl es["JobAttribu tes"].Columns["InternalJo bID"]);
The 'child' tables may or may not contain any records that relate to a
parent record.
I have a BindingSource instance that links a DataGridView with the data
table. The BindingSource has a CurrentChanged event on it, and the event
code updates the database if anything has changed (it then goes on to load
the child tables if they do not already have the appropriate records for
the
new parent record - this stops [in some cases] hundreds of records being
read that will never be displayed/used). It is during the database update
that the exception is triggered.
The only other thing that might be relevant is that the parent table
(JobsDataTable) has a computed column:
JobDataTable.Co lumns.Add("MaxJ obStatus", typeof(int),
"iif(Count(Chil d(JobsContacts) .JobStatus)=0,J obStatus,Max(Ch ild(JobsContact s
).JobStatus))") ;
Thanks for the help - it is much appreciated
Susan
On 12/9/06 14:07, in article eJ************* @TK2MSFTNGP06.p hx.gbl, "Cor
Ligthert [MVP]" <no************ @planet.nlwrote :
>Susan,
Can you show us the piece of code that you use to remove, because in my idea are you using the right approach. The remove should not affect any dataadapter, it just completely removes a datarow from a datatable (as long as it is not a parent row in a relation).
Cor
"Susan Mackay" <ma******@hotma il.comschreef in bericht news:C1******* *************@h otmail.com...
>>I have a data table that is connected to a database table with a data adapter in the 'standard' manner.
However I want to be able to remove selected rows from the data table (i.e. no longer include them in the set that is displayed to the user) but I don't want to delete the corresponding row from the database.
I've tried using the .Rows.Remove() method but an exception is thrown to say I don't have a 'delete' command in the data adapter (which I don't of course).
Because of the way the 'user interface' works, I can't build up an SQL string that represents the current set of records (the user can "add to" and "remove from" the current set of records - there is no underlying SQL statement that represents the totality of the users additions and removals) so I can't just clear the table and re-fill it.
Is there a way to do this?
Thanks
Susan
Cor,
I've stepped through this with the debugger and I am certain that (at least
in the test case I used) the TargetRows array DOES contain records. Also, if
it didn't, then the 'foreach' loop would not be entered and the 'Remove'
method would not be called (that's my understanding anyway!).
I have not included the code that builds the FilterString, but, again at
least in the test case I stepped through, it did contain a valid expression
and the problem still occurred.
Thanks for the continuing support
Susan
On 13/9/06 02:38, in article OI************* *@TK2MSFTNGP03. phx.gbl, "Cor
Ligthert [MVP]" <no************ @planet.nlwrote :
Susan,
First the last part, the update is only affecting those columns that are in
the SQL transaction code of that.
(Stored procedure or commandText).
However are you sure that that DataRow Array TargetRows is filled.
I become suspicious seeing that FilterString.To String(), the Select string
is not the most fine one to make.
Cor
"Susan Mackay" <ma******@hotma il.comschreef in bericht
news:C1******** ************@ho tmail.com...
>Cor,
The relevant part is: (Filterstrin g is a StringBuilder instance containing the row selection statement, JobDataTable is the datatable in question)
DataRow[] TargetRows = JobDataTable.Se lect( FilterString.To String());
foreach( DataRow TargetRow in TargetRows) { JobDataTable.Ro ws.Remove( TargetRow); }
.....
Susan,
Can you try it like this
for (int i = TargetRows.Coun t; i 0; i--)
{DataRow TargetRow = TargetRows[i];
TargetRow.Remov e; }
The TargetRow is AFAIK only a referencetable to your table.
Check the routine, because I have typed this in here. I do this bottom up
looping everytime in another way. (Maybe does the foreach does it as well,
but I did not check it therefore this one, but now maybe I have two answers
in one message)
I do it like that, because collections will sometimes become in trouble when
you start removing a first one as first.
Cor
"Susan Mackay" <ma******@hotma il.comschreef in bericht
news:C1******** ************@ho tmail.com...
Cor,
The relevant part is:
(Filterstring is a StringBuilder instance containing the row selection
statement, JobDataTable is the datatable in question)
DataRow[] TargetRows = JobDataTable.Se lect( FilterString.To String());
foreach( DataRow TargetRow in TargetRows)
{ JobDataTable.Ro ws.Remove( TargetRow); }
You may have already answered the question: the JobDataTable is the parent
of two relationships with other tables in the DataSet - JobAttributes and
JobContacts. Each is set up by code such as the following:
(DatabaseDS is the dataset that holds all of the tables)
DatabaseDS.Rela tions.Add("Jobs Attributes",
DatabaseDS.Tabl es["Jobs"].Columns["InternalJo bID"],
DatabaseDS.Tabl es["JobAttribu tes"].Columns["InternalJo bID"]);
The 'child' tables may or may not contain any records that relate to a
parent record.
I have a BindingSource instance that links a DataGridView with the data
table. The BindingSource has a CurrentChanged event on it, and the event
code updates the database if anything has changed (it then goes on to load
the child tables if they do not already have the appropriate records for
the
new parent record - this stops [in some cases] hundreds of records being
read that will never be displayed/used). It is during the database update
that the exception is triggered.
The only other thing that might be relevant is that the parent table
(JobsDataTable) has a computed column:
JobDataTable.Co lumns.Add("MaxJ obStatus", typeof(int),
"iif(Count(Chil d(JobsContacts) .JobStatus)=0,J obStatus,Max(Ch ild(JobsContact s
).JobStatus))") ;
Thanks for the help - it is much appreciated
Susan
On 12/9/06 14:07, in article eJ************* @TK2MSFTNGP06.p hx.gbl, "Cor
Ligthert [MVP]" <no************ @planet.nlwrote :
>Susan,
Can you show us the piece of code that you use to remove, because in my idea are you using the right approach. The remove should not affect any dataadapter, it just completely removes a datarow from a datatable (as long as it is not a parent row in a relation).
Cor
"Susan Mackay" <ma******@hotma il.comschreef in bericht news:C1******* *************@h otmail.com...
>>I have a data table that is connected to a database table with a data adapter in the 'standard' manner.
However I want to be able to remove selected rows from the data table (i.e. no longer include them in the set that is displayed to the user) but I don't want to delete the corresponding row from the database.
I've tried using the .Rows.Remove() method but an exception is thrown to say I don't have a 'delete' command in the data adapter (which I don't of course).
Because of the way the 'user interface' works, I can't build up an SQL string that represents the current set of records (the user can "add to" and "remove from" the current set of records - there is no underlying SQL statement that represents the totality of the users additions and removals) so I can't just clear the table and re-fill it.
Is there a way to do this?
Thanks
Susan
Cor,
I can't exactly as you requested because the DataRow itself does not have a
Remove() method - the method belongs to the DataRowCollecti on referenced by
(in this case) JobDataTable.Ro ws.
I can see what you are getting at and I've had this problem in other
contexts - removing the early elements form a collection upsets the indexing
for all subsequent items. This is also why the 'foreach' enumerator is
effectively read only.
What does work is:
DataRow[] TargetRows = JobDataTable.Se lect( FilterString.To String());
for( int Index = TargetRows.Leng th - 1; Index >= 0; Index--)
{
DataRow TargetRow = TargetRow[Index];
JobDataTable.Re move( TargetRow);
}
Actually the code as I originally presented it also works because I've found
the problem: and its not directly related to anything I mentioned in this
thread (isn't it always the way - you never get all of the information!!!) .
The problem occurs when the 'current' row (as seen by a BindingSource linked
to the data table) is removed from the data table. As mentioned in the
original posting, I have an CurrentChanged event on this BindingSource.
In this case, when the 'current' record is removed, the binding source
naturally selects a new 'current' record and triggers the event which tries
to update the database with any changes. Probably because of some internal
operation sequence within the Remove() method and the event processing of
the Binding Source, the update procedure must still see the 'deleted' record
still in the collection and tries to delete the record from the database.
Having found the problem, I've now decided on another approach to this whole
thing which avoids any attempts to remove the 'current' record and
everything works nicely.
So thank you for your help and for helping me to more fully understand what
is going on.
Cheers
Susan
On 13/9/06 15:14, in article #z************* *@TK2MSFTNGP04. phx.gbl, "Cor
Ligthert [MVP]" <no************ @planet.nlwrote :
Susan,
Can you try it like this
for (int i = TargetRows.Coun t; i 0; i--)
{DataRow TargetRow = TargetRows[i];
TargetRow.Remov e; }
The TargetRow is AFAIK only a referencetable to your table.
Check the routine, because I have typed this in here. I do this bottom up
looping everytime in another way. (Maybe does the foreach does it as well,
but I did not check it therefore this one, but now maybe I have two answers
in one message)
I do it like that, because collections will sometimes become in trouble when
you start removing a first one as first.
Cor
"Susan Mackay" <ma******@hotma il.comschreef in bericht
news:C1******** ************@ho tmail.com...
>Cor,
The relevant part is: (Filterstrin g is a StringBuilder instance containing the row selection statement, JobDataTable is the datatable in question)
DataRow[] TargetRows = JobDataTable.Se lect( FilterString.To String());
foreach( DataRow TargetRow in TargetRows) { JobDataTable.Ro ws.Remove( TargetRow); }
You may have already answered the question: the JobDataTable is the parent of two relationships with other tables in the DataSet - JobAttributes and JobContacts. Each is set up by code such as the following: (DatabaseDS is the dataset that holds all of the tables)
DatabaseDS.Rela tions.Add("Jobs Attributes", DatabaseDS.Tabl es["Jobs"].Columns["InternalJo bID"], DatabaseDS.Tabl es["JobAttribu tes"].Columns["InternalJo bID"]);
The 'child' tables may or may not contain any records that relate to a parent record.
I have a BindingSource instance that links a DataGridView with the data table. The BindingSource has a CurrentChanged event on it, and the event code updates the database if anything has changed (it then goes on to load the child tables if they do not already have the appropriate records for the new parent record - this stops [in some cases] hundreds of records being read that will never be displayed/used). It is during the database update that the exception is triggered.
The only other thing that might be relevant is that the parent table (JobsDataTable ) has a computed column: JobDataTable.Co lumns.Add("MaxJ obStatus", typeof(int), "iif(Count(Chi ld(JobsContacts ).JobStatus)=0, JobStatus,Max(C hild(JobsContac ts ).JobStatus))" );
Thanks for the help - it is much appreciated
Susan
On 12/9/06 14:07, in article eJ************* @TK2MSFTNGP06.p hx.gbl, "Cor Ligthert [MVP]" <no************ @planet.nlwrote :
>>Susan,
Can you show us the piece of code that you use to remove, because in my idea are you using the right approach. The remove should not affect any dataadapter , it just completely removes a datarow from a datatable (as long as it is not a parent row in a relation).
Cor
"Susan Mackay" <ma******@hotma il.comschreef in bericht news:C1****** **************@ hotmail.com... I have a data table that is connected to a database table with a data adapter in the 'standard' manner.
However I want to be able to remove selected rows from the data table (i.e. no longer include them in the set that is displayed to the user) but I don't want to delete the corresponding row from the database.
I've tried using the .Rows.Remove() method but an exception is thrown to say I don't have a 'delete' command in the data adapter (which I don't of course).
Because of the way the 'user interface' works, I can't build up an SQL string that represents the current set of records (the user can "add to" and "remove from" the current set of records - there is no underlying SQL statement that represents the totality of the users additions and removals) so I can't just clear the table and re-fill it.
Is there a way to do this?
Thanks
Susan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: frank |
last post by:
I have two DataTables, A and B. Both have the primary key "CID". How do I
remove all entries in Table A from Table B (with the same PK)?
|
by: Junkguy |
last post by:
I'm having difficulty deleting rows from a datagrid. I want to put a "delete"
button on a form and achieve the same functionality as hitting the "delete"
key on the keyboard for the selected row of a datagrid.
I really want to do it generically so I have subclassed datagrid and made my
own delete row method but I can only get it to work for datasources that are
datatables or dataviews.
Specifically when the datasource is a DataSet I...
|
by: Agnes |
last post by:
I need to Load 4thousand record into a datagrid for the user to choose.
After the user click the row, I will save it.
Now, How can I remove the uncheck row.
Dim myDelRowArray() As DataRow = dtRvDetail.Select("check = false ")
Me.dtRvDetail.Rows.Remove(myDelRowArray) <-- I know there is error, since i
cannot delete the datarowarray.
Any simple and easy way ??
thanks a lot
|
by: Niyazi |
last post by:
Hi all,
I have a dataTable that contains nearly 38400 rows.
In the dataTable consist of 3 column.
column 1 Name: MUHNO
column 2 Name: HESNO
Column 3 Name: BALANCE
Let me give you some example first:
|
by: Rich |
last post by:
Hello,
I am populating a datagridview from a datatable and filtering the number of
rows with a dataview object. Is there a way to retrieve the rows displayed
by the datagridview into a separate datatable without having to loop through
each column in the datagridview? Or is there a way to retrieve the rows from
the original datatable filtered by the dataview into a separate table? I
only want to copy the rows from the main table that...
| |
by: NAdir |
last post by:
Hi, thank you for your help.
My VB.Net application contains a document that the user can refresh at any
time.
The refresh works fine and needs to loop through few datatables (hundreds of
rows). This works fine until I delete some rows in two tables. Just after the
delete if I do the refresh there is a huge memory allocated and the time
needed to perform the refresh increase, the memory and time continue to
increase on each refresh until I...
|
by: Hamed |
last post by:
Hello
I have a DataTable bound to a DataGrid. During working with the grid, some
detached rows are created internally by the grid. I want to remove the
detached rows from the DataTable but calling myDataTable.Rows.Remove(myRow)
have no effect on it. What am I missing?
I tried to add the row and then delete and then call AcceptChanges but no
success.
|
by: karthick |
last post by:
Hi,
I am reiterating through a Datatable and deleting few rows based on
the user's selection (with the index ref). I use
datatable.rows.Delete() for this purpose. But if I select three
rows, it just deletes only two rows; any idea ?.
Any help is much appreciated. Thanks.
Karthick
|
by: balabaster |
last post by:
Hi, I've been bashing my head against this since Friday and it's driving me nuts.
I've got an EntitySet(Of T) (LINQ) which is serialized to/from the viewstate by overriding the LoadViewState and SaveViewState methods. I've confirmed that this object is serialized/deserialized properly - so I know this bit is working as it should and when it should.
I have created a table template in which I have a header row which is just header text for...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
| |
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |