Execl資料匯入Sql Server表

2021-06-05 07:22:52 字數 1730 閱讀 5421

//將execl資料放入dataset

public dataset execleds(string filenameurl, string table)

//匯入按鈕事件

protected void button1_click(object sender, eventargs e)

string isxls = system.io.path.getextension(fileupload1.filename).tostring().tolower();

if (isxls != ".xls")

string strpath = fileupload1.postedfile.filename.tostring();   //獲取execle檔案路徑

string filename = fileupload1.filename;                       //獲取execle檔名

dataset ds = execleds(strpath, filename);

datarow dr = ds.tables[0].select();                        //定義乙個datarow陣列

int rowsnum = ds.tables[0].rows.count;

if (rowsnum == 0)

else

;string insertsqlstr = @"insert into t_customer

(customercode,customername,cityid,address,telareacode,

telephone,telextno,faxareacode,fax,websiteurl,

sourceid,statusid,typeid,levelid,industryid,createuserid)

values ('','',,'','','','','','','',,,,,,'' ";

insertsqlstr = string.format(insertsqlstr, param);

insertsqlstr += @")";

string sqlcheck = "select  *  from t_customer where customername='" + customername + "'";

dataset dss = dbhelpersql.query(sqlcheck);

if (dss.tables[0].rows.count <= 0)

catch (exception ex)

}else

}response.write("");}}

//核對客戶**是否存在

public string checksource(string sourcename)

else

}//核對客戶狀態是否存在

public string checkstatus(string status)

else

}//核對客戶型別是否存在

public string checktype(string type)

else

}//核對客戶級別是否存在

public string checklevel(string level)

else

}//核對客戶所屬行業是否存在

public string checkindustry(string industry)

else

}

Execl資料匯入SQL Server

將execl 資料匯入進資料庫 可以指定列 也可以 注意 該語句只能在本地資料庫執行 如果連線的是遠端伺服器 應到該伺服器上執行語句 設定伺服器全域性配置 啟用ad hoc distributed queries 該元件存在 安全隱患 所以預設是關閉 exec sp configure show a...

Execl資料匯入資料庫

時區 date default timezone set asia shanghai try catch pdoexception e set time limit 0 ob end clean handle fopen import01.csv r 讀取csv檔案資料 data array if ...

Execl匯入系統

檔案匯入功能 前台 content js jquery.ajaxfileupload.js 上傳1 function bingxianguploadfile 16else 20 21 error function data,status,e 伺服器響應失敗處理函式 2225 26 27 28else...