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

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);
                //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();
                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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.