从Excel到griedview的imoprt数据 [英] imoprt data from excel to griedview
本文介绍了从Excel到griedview的imoprt数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有这些都是我通过文件上传器控件将excel文件保存在服务器上的文件夹中的.
现在我想将此文件导入griedview bt,并给出错误:
外部表未采用预期格式".代码为:
hii all i have saved excel file through file uploader control in a folder at server.
now i want to import this file to griedview bt its giving error:
"External table is not in expected format".the code is:
if (excelfileuploader.HasFile)
{
string filename = excelfileuploader.FileName;
excelfileuploader.SaveAs(Server.MapPath("~/Company/Excel/") + filename);
string conn = ("Provider=Microsoft.Jet.OLEDB.4.0;" +
("Data Source=" + Server.MapPath("~/Company/Excel/")+filename+ ";" +
"Extended Properties=\"Excel 8.0;\""));
string SSQL = "SELECT * from [sheet1$]";
OleDbDataAdapter oleDA = new OleDbDataAdapter(SSQL, conn);
DataSet ds = new DataSet();
try
{
oleDA.Fill(ds);
}
catch (OleDbException ex)
{
throw ex;
}
gridproductdetail.DataSource = ds.Tables[0].DefaultView; // or [ ds ]
gridproductdetail.DataBind();
}
plz help
plz help
推荐答案
; OleDbDataAdapter oleDA =新的OleDbDataAdapter(SSQL,conn); DataSet ds = new DataSet(); 尝试 { oleDA.Fill(ds); } 抓(OleDbException ex) { 扔前 } gridproductdetail.DataSource = ds.Tables [0] .DefaultView; //或[ds] gridproductdetail.DataBind(); }
"; OleDbDataAdapter oleDA = new OleDbDataAdapter(SSQL, conn); DataSet ds = new DataSet(); try { oleDA.Fill(ds); } catch (OleDbException ex) { throw ex; } gridproductdetail.DataSource = ds.Tables[0].DefaultView; // or [ ds ] gridproductdetail.DataBind(); }
请帮助
plz help
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
"Extended Properties=Excel 8.0;";
// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString);
// Open connection with the database.
objConn.Open();
// The code to follow uses a SQL SELECT command to display the data from the worksheet.
// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM ExcelData
", objConn); // Create new OleDbDataAdapter that is used to build a DataSet // based on the preceding SQL SELECT statement. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); // Pass the Select command to the adapter. objAdapter1.SelectCommand = objCmdSelect; // Create new DataSet to hold information from the worksheet. DataSet objDataset1 = new DataSet(); // Fill the DataSet with the information from the worksheet. objAdapter1.Fill(objDataset1, "XLData"); // Bind data to DataGrid control. GridView1.DataSource = objDataset1.Tables[0].DefaultView; GridView1.DataBind(); // Clean up objects. objConn.Close();
", objConn); // Create new OleDbDataAdapter that is used to build a DataSet // based on the preceding SQL SELECT statement. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); // Pass the Select command to the adapter. objAdapter1.SelectCommand = objCmdSelect; // Create new DataSet to hold information from the worksheet. DataSet objDataset1 = new DataSet(); // Fill the DataSet with the information from the worksheet. objAdapter1.Fill(objDataset1, "XLData"); // Bind data to DataGrid control. GridView1.DataSource = objDataset1.Tables[0].DefaultView; GridView1.DataBind(); // Clean up objects. objConn.Close();
.
试试这个
.
try this
这篇关于从Excel到griedview的imoprt数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文