Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have a main DataTable in my Application, From that DataTable i have created a another DataTable using DataView and RowFilter.Now I need to delete that data from My Main Table which data will hold by newly created Table.
Thanks..
Posted
Updated 27-Sep-11 23:34pm
v2
Comments
Tejas Vaishnav 28-Sep-11 5:36am    
Please ask a question in understandable language..

Hi,

I have an idea to solve your problem

your table has columns like id,name,addr,phno...
And you filtered these table data into some table right.

And you can loop that dataview control after filtering .And collect that ids present in filtered data table.

Then write sql command to delete all rows which are present in that array

C#
string strrono="";  
for(int i=0;i<dataview.items.count;i++)>
{
  if(strrno.Length>0)
{
   strrno+=","+dataview.rows[i][0].tosting();
}
else
{
  strrno+=dataview.rows[i][0].tosting();
}
}
string query="delete from tablename where id in("+strrno+")";


I hope you got an idea how to do that

All the Best
 
Share this answer
 
Comments
moon2011 28-Sep-11 6:48am    
thanks alot for your help, but by this way ,
string query="delete from tablename where id in("+strrno+")";

i delete from table in datatbase but i want to delete from the main datatable.
Muralikrishna8811 28-Sep-11 6:59am    
give main tablename instead of tablename
moon2011 28-Sep-11 7:07am    
i have already gave it but it is not working.
Muralikrishna8811 28-Sep-11 7:09am    
Any error?
moon2011 28-Sep-11 7:20am    
there is no error , but the main table still with its hole data without deleting.
I recommend using the multi-table delete syntax, and joining to the archive table for your delete. That way you only delete rows that are in both tables.

Simple Example:

SQL
insert into archive select * from data;
delete data.*
from data
inner join archive on archive.id = data.id;


Beyond that, you may want to consider breaking this down into smaller chunks for better performance. For example:

SQL
insert into archive select * from data where id > 1000 and id <= 2000;
delete data.*
from data
inner join archive on archive.id = data.id
where data.id > 1000 and data.id <= 2000;


From the manual: http://dev.mysql.com/doc/refman/5.1/en/delete.html
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900