好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁(yè) > 知識(shí)庫(kù) > c#將Excel數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼

c#將Excel數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼

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

假如Excel中的數(shù)據(jù)如下:

數(shù)據(jù)庫(kù)建表如下:

其中Id為自增字段:

代碼:

復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Data.SqlClient;

namespace InExcelOutExcel
{
    public partial class ExcelToDB : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FileSvr fileSvr = new FileSvr();
            System.Data.DataTable dt = fileSvr.GetExcelDatatable("C:\\Users\\NewSpring\\Desktop\\Demo\\InExcelOutExcel\\InExcelOutExcel\\excel\\ExcelToDB.xlsx", "mapTable");
            fileSvr.InsetData(dt);
        }
    }
    class FileSvr
    {
        /// summary>
        /// Excel數(shù)據(jù)導(dǎo)入Datable
        /// /summary>
        /// param name="fileUrl">/param>
        /// param name="table">/param>
        /// returns>/returns>
        public System.Data.DataTable GetExcelDatatable(string fileUrl, string table)
        {
            //office2007之前 僅支持.xls
            //const string cmdText = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;IMEX=1';";
            //支持.xls和.xlsx,即包括office2010等版本的   HDR=Yes代表第一行是標(biāo)題,不是數(shù)據(jù);
            const string cmdText = "Provider=Microsoft.Ace.OleDb.12.0;Data Source={0};Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";

            System.Data.DataTable dt = null;
            //建立連接
            OleDbConnection conn = new OleDbConnection(string.Format(cmdText, fileUrl));
            try
            {
                //打開連接
                if (conn.State == ConnectionState.Broken || conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }


                System.Data.DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

                //獲取Excel的第一個(gè)Sheet名稱
                string sheetName = schemaTable.Rows[0]["TABLE_NAME"].ToString().Trim();

                //查詢sheet中的數(shù)據(jù)
                string strSql = "select * from [" + sheetName + "]";
                OleDbDataAdapter da = new OleDbDataAdapter(strSql, conn);
                DataSet ds = new DataSet();
                da.Fill(ds, table);
                dt = ds.Tables[0];

                return dt;
            }
            catch (Exception exc)
            {
                throw exc;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }

        }

        /// summary>
        /// 從System.Data.DataTable導(dǎo)入數(shù)據(jù)到數(shù)據(jù)庫(kù)
        /// /summary>
        /// param name="dt">/param>
        /// returns>/returns>
        public int InsetData(System.Data.DataTable dt)
        {
            int i = 0;
            string lng = "";
            string lat = "";
            string offsetLNG = "";
            string offsetLAT = "";

            foreach (DataRow dr in dt.Rows)
            {
                lng = dr["LNG"].ToString().Trim();
                lat = dr["LAT"].ToString().Trim();
                offsetLNG = dr["OFFSET_LNG"].ToString().Trim();
                offsetLAT = dr["OFFSET_LAT"].ToString().Trim();

                //sw = string.IsNullOrEmpty(sw) ? "null" : sw;
                //kr = string.IsNullOrEmpty(kr) ? "null" : kr;

                string strSql = string.Format("Insert into DBToExcel (LNG,LAT,OFFSET_LNG,OFFSET_LAT) Values ('{0}','{1}',{2},{3})", lng, lat, offsetLNG, offsetLAT);

                string strConnection = ConfigurationManager.ConnectionStrings["ConnectionStr"].ToString();
                SqlConnection sqlConnection = new SqlConnection(strConnection);
                try
                {
                    // SqlConnection sqlConnection = new SqlConnection(strConnection);
                    sqlConnection.Open();
                    SqlCommand sqlCmd = new SqlCommand();
                    sqlCmd.CommandText = strSql;
                    sqlCmd.Connection = sqlConnection;
                    SqlDataReader sqlDataReader = sqlCmd.ExecuteReader();
                    i++;
                    sqlDataReader.Close();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    sqlConnection.Close();

                }
                //if (opdb.ExcSQL(strSql))
                //    i++;
            }
            return i;
        }
    }
}

運(yùn)行結(jié)果:

您可能感興趣的文章:
  • C#導(dǎo)入導(dǎo)出Excel數(shù)據(jù)的兩種方法
  • 讓C# Excel導(dǎo)入導(dǎo)出 支持不同版本Office
  • C#的Excel導(dǎo)入、導(dǎo)出
  • C#實(shí)現(xiàn)Excel導(dǎo)入sqlite的方法
  • C#導(dǎo)入導(dǎo)出EXCEL文件的代碼實(shí)例
  • c#使用EPPlus封裝excel表格導(dǎo)入功能的問題

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

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《c#將Excel數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  將,Excel,數(shù)據(jù),導(dǎo)入,到,數(shù)據(jù)庫(kù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《c#將Excel數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于c#將Excel數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 亚洲国产精品丝袜国产自在线| www.av片| 欧美喷| 海伦市| 人人鲁免费播放视频人人香蕉| 忘忧草在线播放www日本韩国| 猫咪av久久香蕉| 色偷偷.com| 日本国产在线| 亚洲成人a影院青久在线观看| 日本xxxx印度人| 乱L群J最新章节| 爽?好多水?快?深点无码| 校花和校长| 澡堂洗澡吃老头亅j| 亚洲欧美天堂综合一区青草久久久 | а√天堂中文最新版地址| 粉红导航| 夜夜春夜夜爽| 双性皇帝被cao到崩溃H漫画| yy6080午夜理论片| 波多野结衣120分钟AV作品| 精品人妻久久久久一区二区三区 | 好大好深好满撑不住了| 综合色伊人久久一区二区| 美女被免费网在线观看网站| 91香蕉国产在线观看人员| 一级岛国片| 又肉又欲的h文| 托着奶头喂男人吃奶A片奶水网站 大胸奶头晃着喷奶水av日本 | 男男车文各种play| 黑人久久| 国产91臀交在线播放| 老板办公室狂躁秘书在线观看| 偷偷吸允老师的丝袜脚趾| 祖女三代吞吐h短篇| 很狠操| 渡佛男主和女主第一次 | 美国一级特黄大片做受9分钟| 窝窝午夜紫夜看片影院| 大象焦伊人在钱9|