婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > asp.net讀取excel中的數(shù)據(jù)并綁定在gridview

asp.net讀取excel中的數(shù)據(jù)并綁定在gridview

熱門(mén)標(biāo)簽:電銷(xiāo)機(jī)器人 數(shù)據(jù) 地圖標(biāo)注多少錢(qián)一張 ai電銷(xiāo)機(jī)器人對(duì)貸款有幫助嗎 宿遷智能外呼系統(tǒng)排名 廣州銷(xiāo)售外呼系統(tǒng)定制 怎樣給陜西地圖標(biāo)注顏色 400電話辦理信任翰諾科技 云狐人工智能電話機(jī)器人 福州人工智能電銷(xiāo)機(jī)器人加盟
前臺(tái)label,DropDownList,gridview控件

aspx.cs核心代碼:
復(fù)制代碼 代碼如下:

using System.Data.OleDb;//需要引入命名
public void Excel_Click(object sender, EventArgs e)
{
if (this.AttachmentFile.Value == "" this.Label1.Text == "" DropDownList2.SelectedValue == "")
{
Response.Write("script>window.alert('請(qǐng)選擇要導(dǎo)入的文件')/script>");
}
if (this.AttachmentFile.Value != "" this.DropDownList2.SelectedValue == "")
{
HttpFileCollection files = HttpContext.Current.Request.Files;
HttpPostedFile postedFile = files[0];
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
postedFile.SaveAs("\\\\localhost\\文件夾\\" + fileName);
}
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "\\\\localhost\\文件夾\\" + fileName + ";Extended Properties=Excel 8.0;";//this.AttachmentFile.Value.ToString()
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable sheetNames = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
foreach (DataRow dr in sheetNames.Rows)
{
DropDownList2.Items.Add(dr[2].ToString());
}
this.Label1.Text = "\\\\localhost\\文件夾\\" + fileName;//this.AttachmentFile.Value.ToString();
conn.Close();
}
if (this.Label1.Text.ToString() != "" this.DropDownList2.SelectedValue != "")// this.DropDownList1.SelectedValue.ToString() != "全部"
{

//綁定到gridview
GridView1.DataSource = createDataSource(DropDownList2.SelectedValue.ToString(), this.Label1.Text.ToString());//, this.DropDownList1.SelectedValue.ToString()
GridView1.DataBind();


}


}
//以Excel為數(shù)據(jù)源獲取數(shù)據(jù)集
private DataSet createDataSource(string select, string lable)

{
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + lable + ";Extended Properties=Excel 8.0;";
string strsql = "select 登記號(hào)碼,姓名,日期,簽到時(shí)間,簽退時(shí)間,部門(mén) from [" + select + "] order by 部門(mén),日期,姓名";//excel表格的字段
OleDbConnection conn = new OleDbConnection(strCon);
OleDbDataAdapter da = new OleDbDataAdapter(strsql, conn);
try
{
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
return ds;
}
catch (Exception e)
{
Response.Write("script>window.alert('沒(méi)有數(shù)據(jù),或者" + e.Message + "')/script>");
return null;
}
}

以上是插入07以前版本excel

如果07版本以后只需要做小小修改
復(fù)制代碼 代碼如下:

string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + lable + ";Extended Properties=Excel 12.0;";
您可能感興趣的文章:
  • asp.net gridview代碼綁定
  • asp.net ListView 數(shù)據(jù)綁定
  • asp.net中將數(shù)據(jù)庫(kù)綁定到DataList控件的實(shí)現(xiàn)方法與實(shí)例代碼
  • asp.net中綁定TextBox回車(chē)事件的解決方法
  • asp.net中ListBox 綁定多個(gè)選項(xiàng)為選中及刪除實(shí)現(xiàn)方法
  • ASP.NET中ListView(列表視圖)的使用前臺(tái)綁定附源碼
  • asp.net數(shù)據(jù)綁定DataBind使用方法
  • Asp.net中的數(shù)據(jù)綁定Eval和Bind應(yīng)用示例
  • ASP.NET MVC數(shù)組模型綁定詳解

標(biāo)簽:焦作 大興安嶺 綿陽(yáng) 曲靖 延安 新疆 黃南 宜春

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net讀取excel中的數(shù)據(jù)并綁定在gridview》,本文關(guān)鍵詞  asp.net,讀取,excel,中的,數(shù)據(jù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net讀取excel中的數(shù)據(jù)并綁定在gridview》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于asp.net讀取excel中的數(shù)據(jù)并綁定在gridview的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 阿尔山市| 陵水| 迭部县| 镇坪县| 会同县| 剑川县| 上高县| 榕江县| 太湖县| 峨眉山市| 尼木县| 夹江县| 延川县| 会昌县| 耿马| 义马市| 策勒县| 广昌县| 徐州市| 正阳县| 金乡县| 孝感市| 宾阳县| 文安县| 车险| 兴义市| 仁布县| 马关县| 阿荣旗| 泰安市| 安宁市| 灯塔市| 临邑县| 盐城市| 茶陵县| 金昌市| 获嘉县| 桦南县| 乌拉特前旗| 廊坊市| 安国市|