如何清除包含列名的任何数据的数据表? [英] how to clear the datatable with out any data including the column names?
本文介绍了如何清除包含列名的任何数据的数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用 dt.columns.clear()
清除我的数据表但是数据表仍然有一个空列,我想删除它。 />
如何做到这一点?
您对这方面的帮助将受到高度赞赏......!
先谢谢.. :)
i tried to clear my datatable using dt.columns.clear()
but still the datatable is having one empty column and i want to remove it.
how to do this?
your help in this regard would be highly appreciated...!
Thanks in Advance..:)
推荐答案
嗯。
我觉得你错了:
Um.
I think you are mistaken:
using (SqlConnection con = new SqlConnection(strConnect))
{
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("SELECT TOP 100 Title from Videos", con);
da.Fill(dt);
Console.WriteLine("{0}:{1}", dt.Columns.Count, dt.Rows.Count);
dt.Columns.Clear();
Console.WriteLine("{0}:{1}", dt.Columns.Count, dt.Rows.Count);
}
给:
Gives:
1:100
0:100
首先看看你的代码,看看你到底在做什么,以及你想要实现的目标。
So start by looking at your code, and see exactly what you are doing, and what you are trying to achieve.
dt.Columns.Clear( );
dt.Rows.Clear();
dt.Columns.Clear();
dt.Rows.Clear();
这篇关于如何清除包含列名的任何数据的数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文