做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

asp.net Excel轉(zhuǎn)換為SQL Server的方法

來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-27 22:44:26
文檔

asp.net Excel轉(zhuǎn)換為SQL Server的方法

asp.net Excel轉(zhuǎn)換為SQL Server的方法:1.功能分析 通過Microsoft.Jet.OLEDB.4.0方式可實現(xiàn)使用ADO.NET訪問Excel的目的,如以下示例代碼為連接Excel數(shù)據(jù)的字符串: 代碼如下:string strOdbcCon = @Provider=Microsoft.Jet.OLEDB.4.0;Persist Security I
推薦度:
導(dǎo)讀asp.net Excel轉(zhuǎn)換為SQL Server的方法:1.功能分析 通過Microsoft.Jet.OLEDB.4.0方式可實現(xiàn)使用ADO.NET訪問Excel的目的,如以下示例代碼為連接Excel數(shù)據(jù)的字符串: 代碼如下:string strOdbcCon = @Provider=Microsoft.Jet.OLEDB.4.0;Persist Security I

1.功能分析
通過Microsoft.Jet.OLEDB.4.0方式可實現(xiàn)使用ADO.NET訪問Excel的目的,如以下示例代碼為連接Excel數(shù)據(jù)的字符串:
代碼如下:
string strOdbcCon = @"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=D:\2010年圖書銷售情況.xls;Extended Properties=Excel 8.0";

2.實施方法
程序開發(fā)步驟:
(1)新建一個網(wǎng)站,命名為25,其主頁默認(rèn)為Default.aspx。
(2)Default.aspx頁面中添加一個Table表格,用來布局頁面,然后在該Table表格中添加一個iframe框架、兩個Button控件和一個GridView控件,其中,iframe框架用來顯示原始Excel數(shù)據(jù)表中的數(shù)據(jù);Button控件分別用來將指定Excel中的數(shù)據(jù)表導(dǎo)入到SQL Server數(shù)據(jù)庫中和將導(dǎo)入SQL Server數(shù)據(jù)庫中的Excel數(shù)據(jù)綁定到GridView控件上;GridView控件用來顯示導(dǎo)入SQL Server數(shù)據(jù)庫中的Excel數(shù)據(jù)。
(3)程序主要代碼如下。
Default.aspx頁面中,首先自定義一個LoadData方法,該方法為無返回值類型方法,主要用來將Excel數(shù)據(jù)表中的數(shù)據(jù)導(dǎo)入到SQL Server數(shù)據(jù)庫中。LoadData方法實現(xiàn)代碼如下:
代碼如下:
public void LoadData(string StyleSheet)
{
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + Server.MapPath
("usersdb.xls") + ";Extended Properties=Excel 8.0";
OleDbConnection myConn = new OleDbConnection(strCon);
myConn.Open(); //打開數(shù)據(jù)鏈接,得到一個數(shù)據(jù)集
DataSet myDataSet = new DataSet(); //創(chuàng)建DataSet對象
string StrSql = "select * from [" + StyleSheet + "$]";
OleDbDataAdapter myCommand = new OleDbDataAdapter(StrSql, myConn);
myCommand.Fill(myDataSet, "[" + StyleSheet + "$]");
myCommand.Dispose();
DataTable DT = myDataSet.Tables["[" + StyleSheet + "$]"];
myConn.Close();
myCommand.Dispose();
string strConn = "Data Source=(local);DataBase=Usersdb;Uid=sa;Pwd=";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
for (int j = 0; j < DT.Rows.Count; j++)
{
string UserID = DT.Rows[j][0].ToString();
string EmailAddress = DT.Rows[j][1].ToString();
string FirstName = DT.Rows[j][2].ToString();
string LastName = DT.Rows[j][3].ToString();
string Address1 = DT.Rows[j][4].ToString();
string Address2 = DT.Rows[j][5].ToString();
string City = DT.Rows[j][6].ToString();
string strSql = "insert into Usersdb(EmailAddress,FirstName,
LastName,Address1,Address2,City) ";
strSql = strSql + "values('" + EmailAddress + "','" + FirstName + "',
'" + LastName + "','" + Address1 + "','" + Address2 + "','" + City + "')";
SqlCommand comm = new SqlCommand(strSql, conn);
comm.ExecuteNonQuery();
if (j == DT.Rows.Count - 1)
{
Label1.Visible = true;
}
else
{
Label1.Visible = false;
}
}
conn.Close();
}

單擊【Excel數(shù)據(jù)寫入數(shù)據(jù)庫中】按鈕,定義一個string類型的變量,用來為LoadData傳入?yún)?shù),然后調(diào)用LoadData自定義方法將指定的Excel中的數(shù)據(jù)表導(dǎo)入到SQL Server數(shù)據(jù)庫中?!綞xcel數(shù)據(jù)寫入數(shù)據(jù)庫中】按鈕的Click事件代碼如下:
代碼如下:
protected void Button1_Click(object sender, EventArgs e)
{
string StyleSheet = "Sheet1";
LoadData(StyleSheet);
}

單擊【顯示導(dǎo)入SQL的Excel數(shù)據(jù)】按鈕,將導(dǎo)入SQL Server數(shù)據(jù)庫中的Excel數(shù)據(jù)綁定到GridView控件上,顯示在網(wǎng)頁中?!撅@示導(dǎo)入SQL的Excel數(shù)據(jù)】按鈕的Click事件代碼如下:
代碼如下:
protected void Button2_Click(object sender, EventArgs e)
{
string strConn = "Data Source=(local);DataBase=Usersdb;Uid=sa;Pwd=";
string sqlstr="select * from Usersdb";
SqlConnection conn = new SqlConnection(strConn);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr,conn);
DataSet ds = new DataSet();
conn.Open();
myda.Fill(ds, "Usersdb");
GridView1.DataSource = ds;
GridView1.DataBind();
conn.Close();
}

說明:程序中進(jìn)行與Excel和SQL Server數(shù)據(jù)庫相關(guān)的操作時,首先需要分別添加System.Data.OleDb和System.Data.SqlClient命名空間。
3.補(bǔ)充說明
除了可以將Excel中數(shù)據(jù)導(dǎo)入到SQL Server數(shù)據(jù)庫外,還可以將其轉(zhuǎn)換為.txt文本文件格式,或者導(dǎo)入到Access或Oracle等數(shù)據(jù)庫中。

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

asp.net Excel轉(zhuǎn)換為SQL Server的方法

asp.net Excel轉(zhuǎn)換為SQL Server的方法:1.功能分析 通過Microsoft.Jet.OLEDB.4.0方式可實現(xiàn)使用ADO.NET訪問Excel的目的,如以下示例代碼為連接Excel數(shù)據(jù)的字符串: 代碼如下:string strOdbcCon = @Provider=Microsoft.Jet.OLEDB.4.0;Persist Security I
推薦度:
標(biāo)簽: excel 的方法 sql
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 兴宁市| 房山区| 莫力| 台北市| 无棣县| 桃园市| 九龙县| 香河县| 昌图县| 象州县| 长子县| 元氏县| 四子王旗| 黄梅县| 昌乐县| 深圳市| 河间市| 玉林市| 景洪市| 万载县| 巨野县| 休宁县| 九江县| 华安县| 平阴县| 永丰县| 平和县| 姜堰市| 集安市| 石林| 运城市| 鸡泽县| 东乡| 中卫市| 凤冈县| 沅江市| 南丰县| 沙田区| 遂宁市| 灌南县| 临颍县|