Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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..:)
Posted

Um.
I think you are mistaken:
C#
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.
 
Share this answer
 
dt.Columns.Clear();
dt.Rows.Clear();
 
Share this answer
 
Comments
Seshu--The Baadshah 8-Apr-15 1:00am    
i just made my datatable as null by using dt=null and its working fine..
Thank you for your answer

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