Stack Exchange
Import Excel Sheet in Asp.Net
I need to ask about import excel sheet question with child-parent relationship.
below i have a sample table 
then I need to import this table like that this format -->
        IndustryName | IndustryCode | CategoryName | CategoryCode | CategoryValue | SubCategoryName | SubCategoryCode | SubCategoryValue
        IndustryName1  IndustCode     CatName        CatCode        CatValue        SubCatName        SubCatCode        SubCatValue
        IndustryName1  IndustCode     CatName        CatCode        CatValue        SubCatName        SubCatCode        SubCatValue

On the SubCategory line There are two spaces in front of SubCategoryCode.Its Fixed. 
Anybody Have an idea how can i make it ? 

You can import your excel data to a DataSet and then play around with dataset and create your desired table. For e.g when iterating through the first column you can check the string if it has 2 spaces before then add it to subcategory column and others to the category column. All you have to do is iterate through the rows of the DataSet and store your required values in a new datatable.
public DataSet ExcelToDS(string Path, string sheetname)
        {
            string xlsConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + ";Extended Properties=Excel 8.0;";
            string xlsxConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Path + ";Extended Properties=Excel 12.0";
            using (OleDbConnection conn = new OleDbConnection(xlsxConn))
            {
                conn.Open();
                string strExcel = "select * from [" + sheetname + "$]";
                OleDbDataAdapter oledbda = new OleDbDataAdapter(strExcel, xlsxConn);
                DataSet ds = new DataSet();
                oledbda.Fill(ds, sheetname);
                conn.Close();
                return ds;
            }
        }


Thanks for reply. But my problem on not import the excel table. Actually how to convert it above sql format.

I have written that you will need to iterate through the rows available and generate your desired table by storing required values in it.@ekremtapan
