string ds = Session["nam"].ToString(); string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + ds + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection con = new OleDbConnection(conStr); con.Open(); System.Data.DataTable dt = null; dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (dt == null) { Response.Write("no shhet found"); ; } DataTable table = new DataTable(); //DataRow dr = null; DataRow row=null; DataColumn column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "id"; table.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "item"; table.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "item2"; table.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "item3"; table.Columns.Add(column); OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [" + DropDownList1.SelectedItem.ToString() + "]", con); DataSet objDataSet = new DataSet(); DataTable dt1 = new DataTable(); adapter.Fill(objDataSet); dt1 = objDataSet.Tables[0]; adapter.Fill(dt1); row = table.NewRow(); int number_of_columns = dt1.Columns.Count; // Response.Write(number_of_columns); int number_of_rows = objDataSet.Tables[0].Rows.Count / 2; row["item"] = DropDownList1.SelectedItem.ToString(); row["item2"] = number_of_rows; row["item3"] = number_of_columns; row["id"] = LabelUpload.Text; // table.NewRow(); table.Rows.Add(row); //table.Rows.Add(table.NewRow()); GridView1.DataSource =table; GridView1.DataBind();
DataRow newRow = dt.NewRow(); newRow[NAME] = "New row"; dt.Rows.Add(newRow);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)