国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
把Excel數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫(kù)

把Excel數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫(kù)

public void Import(DataSet ds, string table)
        {
            SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);
            conn.Open();
            SqlBulkCopy sbc = new SqlBulkCopy(conn);
            sbc.DestinationTableName = table;// ds.Tables[0].TableName;
            //將數(shù)據(jù)集合和目標(biāo)服務(wù)器的字段對(duì)應(yīng)
            for (int q = 0; q < ds.Tables[0].Columns.Count; q++)
            {
                sbc.ColumnMappings.Add(ds.Tables[0].Columns.ColumnName, ds.Tables[0].Columns.ColumnName);
            }
            try
            {
                sbc.WriteToServer(ds.Tables[0]);//把數(shù)據(jù)插入到數(shù)據(jù)庫(kù)中   
            }
            catch (Exception e)
            {
                throw new Exception("Import Failed");
            }
            finally
            {
                ds.Dispose();
                conn.Close();
                sbc.Close();
            }
        }
//把Excel文件導(dǎo)入到數(shù)據(jù)庫(kù)中
        protected void BtnImport_Click(object sender, EventArgs e)
        {
            if (this.FileUpload1.HasFile == true)
            {
                ArrayList sheetname = ExcelSheetName(this.FileUpload1.PostedFile.FileName);
                ds = ExcelDataSource(this.FileUpload1.PostedFile.FileName, sheetname[0].ToString());
                int count = ds.Tables[0].Rows.Count;
                int ret = stuBll.Import(ds, "zxsjbxx");
                if (ret == 1)
                {
                   this.ClientScript.RegisterStartupScript(this.GetType(), "return1",string.Format("<script language=javascript>alert(\"" + "數(shù)據(jù)導(dǎo)入成功!"+ "\");</script>"));
                    //Response.Write("<script language=javascript>alert('數(shù)據(jù)導(dǎo)入成功!');</script>");
                }
                else
                {
                   this.ClientScript.RegisterStartupScript(this.GetType(), "return1",string.Format("<script language=javascript>alert(\"" +"數(shù)據(jù)導(dǎo)入失敗!請(qǐng)重試!" + "\");</script>"));
                }
            }
            else
            {
                this.ClientScript.RegisterStartupScript(this.GetType(),"return1", string.Format("<script language=javascript>alert(\"" +"沒有選擇文件!" + "\");</script>"));
            }
        }
        //獲得Excel中的所有sheetname。
        public ArrayList ExcelSheetName(string filepath)
        {
            ArrayList al = new ArrayList();
            string strConn;
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + filepath + "';Extended Properties='Excel 8.0;HDR=yes'";
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            System.Data.DataTable  sheetNames =conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, newobject[] { null, null, null, "TABLE" });
            conn.Close();
            foreach (DataRow dr in sheetNames.Rows)
            {
                al.Add(dr[2]);
            }
            return al;
        }
        //該方法實(shí)現(xiàn)從Excel中導(dǎo)出數(shù)據(jù)到DataSet中,其中filepath為Excel文件的絕對(duì)路徑,sheetname為表示那個(gè)Excel表;
        public DataSet ExcelDataSource(string filepath, string sheetname)
        {
            string strConn;
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + filepath + "';Extended Properties='Excel 8.0;HDR=yes'";
            OleDbConnection conn = new OleDbConnection(strConn);
            OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "]", strConn);
            DataSet ds = new DataSet();
            oada.Fill(ds);
            return ds;
  
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
.net導(dǎo)入Excel 獲取工作表名
用gridview顯示來自excel表格里的數(shù)據(jù)
利用OleDb方式對(duì)DataSet 和 Excel 數(shù)據(jù)快速導(dǎo)入導(dǎo)出
如何將Excel數(shù)據(jù)批量導(dǎo)入SQL數(shù)據(jù)庫(kù)
C#操作Excel(導(dǎo)入導(dǎo)出)
C# 讀取Excel文件 .
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服