Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 26, 2010 10:41 AM by alextki
0 Points
1 Post
Oct 26, 2010 10:25 AM|LINK
I have a excel sheet and I want to make the 2nd row my header column and read the data from the 3rd row, considering 2nd row is the Column name.
ASP.NET and c#.net/vb.net code
vusual studio C# C#.net excel to html c # excel upload
Member
60 Points
25 Posts
Oct 26, 2010 10:41 AM|LINK
Get all your xls sheet data into a dataset based on conditions, then loop through the dataset to start from 2nd Row
//Read the Excel Sheet Data and put into the Data Table
objModConn.Open();
objModAdapter.SelectCommand = objModCmdSelect;
objModAdapter.Fill(dsSource);
objModConn.Close();
dtData.Clear();
dtData.Columns[colName].Unique =
{
{ dtData.ImportRow(dtData1.Rows[r]); }
}
Raj.Gupta
0 Points
1 Post
How to Read excel sheet from 3rd (nth) row using Oledb provider
Oct 26, 2010 10:25 AM|LINK
I have a excel sheet and I want to make the 2nd row my header column and read the data from the 3rd row, considering 2nd row is the Column name.
ASP.NET and c#.net/vb.net code
vusual studio C# C#.net excel to html c # excel upload
alextki
Member
60 Points
25 Posts
Re: How to Read excel sheet from 3rd (nth) row using Oledb provider
Oct 26, 2010 10:41 AM|LINK
Get all your xls sheet data into a dataset based on conditions, then loop through the dataset to start from 2nd Row
//Read the Excel Sheet Data and put into the Data Table
objModConn.Open();
objModAdapter.SelectCommand = objModCmdSelect;
objModAdapter.Fill(dsSource);
objModConn.Close();
dtData.Clear();
dtData.Columns[colName].Unique =
string modSql = "SELECT * FROM [" + sheetName.ToString() + "] where Location in('System','" + projName + "')";string modConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source=" + sourceFilePath + ";" + "Extended Properties=Excel 8.0;";OleDbConnection objModConn = new OleDbConnection(modConnectionString);OleDbCommand objModCmdSelect = new OleDbCommand(modSql, objModConn);OleDbDataAdapter objModAdapter = new OleDbDataAdapter();DataSet dsSource = new DataSet();DataTable dtData1 = dsSource.Tables[0];DataTable dtData = dtData1.Clone();false;// Write Data from dtData1 to dtData{
for (int r = 0; r < dtData1.Rows.Count; r++)try{ dtData.ImportRow(dtData1.Rows[r]); }
{
}
catch (Exception Exins)Console.WriteLine(Exins.Message); }