从另一个数据表中删除数据表 [英] delete datatable from another datatable

查看:103
本文介绍了从另一个数据表中删除数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我的应用程序中有一个主数据表,从该数据表中我使用DataView和RowFilter创建了另一个数据表.现在我需要从我的主表中删除该数据,该数据将由新创建的表保存.
谢谢..

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..

推荐答案



我有一个解决您问题的想法

您的表中有ID,名称,地址,phno等列...
然后将这些表数据过滤到一些表中.

然后,您可以在过滤后循环该dataview控件.并收集存在于过滤后的数据表中的ID.

然后编写sql命令以删除该数组中存在的所有行

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

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


我建​​议使用多表删除语法,并加入存档表以进行删除.这样,您只删除两个表中的行.

简单示例:

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:

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:

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;



从手册中:http://dev.mysql.com/doc/refman/5.1/en/delete.html



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


这篇关于从另一个数据表中删除数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆