日期:2014-05-17 浏览次数:20619 次
string sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + FileUpload1.PostedFile.FileName.ToString() + ";" + "Extended Properties=\"Excel 8.0;\"";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet ds = new DataSet();
objAdapter1.Fill(ds,"dt");
/* 从第二行开始读还是同样的问题
for (int i = 1; i < ds.Tables["dt"].Rows.Count; i++)
{
string 序号 = ds.Tables["dt"].Rows[i][0].ToString();
string 姓名 = ds.Tables["dt"].Rows[i][0].ToString();
string 身份证号 = ds.Tables["dt"].Rows[i][0].ToString();
string 性别 = ds.Tables["dt"].Rows[i][0].ToString();
string 工作单位 = ds.Tables["dt"].Rows[i][0].ToString();
string 联系电话 = ds.Tables["dt"].Rows[i][0].ToString();
string 报考单位 = ds.Tables["dt"].Rows[i][0].ToString();
string 报考岗位 = ds.Tables["dt"].Rows[i][0].ToString();
string 准考证号 = ds.Tables["dt"].Rows[i][0].ToString();
string 成绩 = ds.Tables["dt"].Rows[i][0].ToString();
string 名次 = ds.Tables["dt"].Rows[i][0].ToString();
}
GridView1.DataSource =ds.Tables["dt"];
GridView1.DataBind();
*/
GridView1.DataSource = ds;
GridView1.DataBind();