C#连接Execl// Create connection string variable. Modify the "Data Source" // parameter as appropriate for your environment. string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("../Book1.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();
// parameter as appropriate for your environment.
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("../Book1.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();
"Data Source=" + Server.MapPath("../Book1.xls") + ";" +
"Extended Properties=Excel 8.0;";
-----------------------------------------------------------------------
这个连接字符串基本能解决问题了!!你可以在数据库直接导入.而不需要程序实现!!
{
string strCon;
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("excel.xls") + "; Extended Properties=Excel 8.0;";
OleDbConnection olecon = new OleDbConnection(strCon);
OleDbDataAdapter myda = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strCon);
DataSet myds = new DataSet();
myda.Fill(myds);
return myds;
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = CreateDataSource();
GridView1.DataBind();
}