http://mannpandey.blogspot.com/2009/06/writing-excel-file-with-data-set.html
string strConnstr = "Server=172.16.0.42;Database = dbEBSCONew;User id=gpts;password=gpts;"; SqlConnection con = new SqlConnection(strConnstr); con.Open(); string strQuery; Microsoft.Office.Interop.Excel.Application sXL = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workBook = null; Microsoft.Office.Interop.Excel.Sheets sheets = null; Microsoft.Office.Interop.Excel.Worksheet workSheet = null; //Opening the Record file workBook = sXL.Workbooks.Open("D:\\Customlookupsheet", 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); sheets = workBook.Worksheets; workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item("Occupation"); int rowIndex = 3; toolStripProgressBar1.Minimum = 0; toolStripProgressBar1.Maximum = workSheet.UsedRange.Rows.Count; while (rowIndex <= workSheet.UsedRange.Rows.Count) { Microsoft.Office.Interop.Excel.Range rngParam = workSheet.get_Range("A" + rowIndex.ToString(), "A" + rowIndex.ToString()); string strParam = Convert.ToString(rngParam.Cells.Value2); Microsoft.Office.Interop.Excel.Range rngParam1 = workSheet.get_Range("B" + rowIndex.ToString(), "B" + rowIndex.ToString()); string strParam1 = Convert.ToString(rngParam1.Cells.Value2); strQuery = "Insert into tbOccupation values('" + strParam + "','" + strParam1 + "')"; int x = SqlHelper.ExecuteNonQuery(con, CommandType.Text, strQuery); rowIndex += 1; toolStripProgressBar1.PerformStep(); }