I’m importing data in a SQL Server 2008 database from excel file where the first row is headers (HDR=1). The thing is that the second row is also kind of headers which i don’t really need to be imported. So how do I ignore the second row from that excel (I guess if the first row is the headers, the actual second row in excel is first)?
In MySQL is just about saying IGNORE LINES 1 in the end of import command … How do I do it in SQL Server?
Here is part of the code doing that:
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("Select [task_code],[status_code],[wbs] from [task$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(connectionString);
//Give your Destination table name
sqlBulk.DestinationTableName = "task";
sqlBulk.WriteToServer(dReader);
sqlBulk.Close();
Thanks
Use the following: