1
Answer

Getting Specific Data in DataSet Column and export in excel

i have 5 column in my dataset.
name, age,sex, address and contact number
then i have 3 datarows in dataset

i need only name, address and contact number during export in excel..
how can i do that?
im using the using Excel = Microsoft.Office.Interop.Excel;
i only get the 1st row.. not all rows in data set

this is my code for getting the values
 
Microsoft.Office.Interop.Excel.Application ExcelAp = new Microsoft.Office.Interop.Excel.Application();
ExcelAp.Application.Workbooks.Add(Type.Missing);
ExcelAp.Columns.ColumnWidth = 25;
 
int i =0;
foreach( DataRow datarow in DsNow.Tables[0].Rows)
{
      for(i = 0; DsNow.Tables[0].Rows.Count - 1; i ++)
            {
                         ExcelAp.Cells[i + 6, 1] = datarow["name"].ToString();
                         ExcelAp.Cells[i + 6, 2] = datarow["address"].ToString();
                         ExcelAp.Cells[i + 6, 3] = datarow["contactnumber"].ToString(); 
            }
 
please help 
Answers (1)