R.D Ip

R.D Ip

  • NA
  • 76
  • 8.3k

column name 'nwt wt' already belongs to this datatable error

Apr 30 2021 11:21 AM
I am working on c#
 
I am saving a excel sheet
 
but I am facing an error
 
 
but my requirement is same column name in multiple time in excelsheet
 
below is my original requirement
 
 
what i am doing:
 
datatable data assign to the column
 
see below code:
  1. private void AddStatExcelSheet(DataTable pDT, ExcelWorksheet excelWorksheet)    
  2. {    
  3.     DataTable dtCust = new DataTable();    
  4.     
  5.     dtCust.Columns.Add("Net Wt"typeof(double));    
  6.     dtCust.Columns.Add("sx"typeof(int));    
  7.     dtCust.Columns.Add("sd"typeof(double));    
  8.                 
  9.     dtCust.Columns.Add("Net Wt"typeof(double));    
  10.     dtCust.Columns.Add("sx"typeof(int));    
  11.     dtCust.Columns.Add("sd"typeof(double));    
  12.                 
  13.     DataTable dt = dr.CopyToDataTable();  
  14.     foreach (DataRow Drow in dt.Rows)    
  15.     {    
  16.         DataRow DRowDetailSubDet =   dtCust.NewRow();    
  17.         dtCust["Net Wt"] = Drow["snweight"];    
  18.         dtCust["sx"] = Drow["sqty"];    
  19.         dtCust["sd"] = Drow["sdweight"];    
  20.         dtCust["Net Wt"] = Drow["fnetwt"];    
  21.         dtCust["sx"] = Drow["fsx"];    
  22.         dtCust["sd"] = Drow["fsd"];    
  23.         dtCust.Rows.Add(DRowDetailSubDet);  
  24.     }  
  25. }  
I am trying to add bxc status and fx status but how?
 
please help

Answers (4)