0

Hi

I have an Excel file with two columns. name and number and having some data in that excel file.

Name Number
kumar 9090090909
XYZ 900909099
ABC 1234512345


Now i want to get the data in to asp.net textbox controls.

Can any one help me doing this in Asp.Net

Thanks in Advance

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by mono_jit23
0
OleDbConnection con;
            System.Data.DataTable dt = null;
            string conn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +"Excelfile path with ExcelFileName +
                                                                                "; Extended Properties=Excel 8.0;";

            con = new OleDbConnection(conn);
            try
            {
                con.Open();
                //get the sheet name in to a table
                dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                String[] excelsheets = new String[dt.Rows.Count];
                int i = 0;
                //using foreach get the sheet name in a string array called excelsheets[] for multiple worksheets.
                foreach (DataRow dr in dt.Rows)
                {
                    excelsheets[i] = dr["TABLE_NAME"].ToString();
                    i++;
                }
                string temp = excelsheets[0].ToString();//sheets will be sorted in alphabetical order.
                DataSet ds = new DataSet();
                string query = "select * from [" + temp + "]";
                OleDbDataAdapter adp = new OleDbDataAdapter(query, con);
                adp.Fill(ds, temp);
             }

I hope from the dataset you can extract your required data and put it into your textbox.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.