Dinesh Santhalingam

Dinesh Santhalingam

  • NA
  • 737
  • 368.5k

How to declare the data table column in c#?

Feb 2 2017 12:22 AM
  1. class details  
  2.    {  
  3.         
  4.        userdetails userdetails = new userdetails();  
  5.        public string last;  
  6.        public DataTable generalinfo = new DataTable();  
  7.        public void loaddata(string [] path)  
  8.        {  
  9.           //Column were declared..............
  10.         /*generalinfo.Columns.Add("Name");  
  11.           generalinfo.Columns.Add("Totalbike");  
  12.           generalinfo.Columns.Add("Inuse");  
  13.           generalinfo.Columns.Add("Time");*/  
  14.           lines = path;  
  15.           //do something............. 
  16.        } 
  17. }
I have a data table .I wish to declare the column for my data table.But If i declared in loaddata its creating some error.Because Loaddata is Run every time.So the Error raised. 
Error:Datacolumn were already belongs to a data table ...
How to declare it before the load data .Please solve my issue?Thanks in advance... 

Answers (9)