///
/// 從exce表中直接匯入到資料庫中
///
///
///
private void barbuttonitem從excel匯入_itemclick(object sender, devexpress.xtrabars.itemclickeventargs e)
//} while (read.nextresult());
//read.close();
//con.close();
//bandedgridview1.bands[0].caption = openfiledialog1.filename + "-" + tablename;
sp = datetime.now - t;
messagebox.show("已經成功開啟excel表" + n + "條記錄;耗時" + sp.totalseconds + "秒", "獲取資料成功");
}catch (oledbexception)
catch (exception ex)
finally}}
bandedgridview1.bands[0].caption = "配件編碼表";
}private void transferdata(string excelfile, string sheetname, string connectionstring)
$]", sheetname);
mycommand = new oledbdataadapter(strexcel, strconn);
mycommand.fill(ds, sheetname);
//如果目標表不存在則建立
string strsql = string.format("if object_id('') is null create table (", sheetname);
foreach (system.data.datacolumn c in ds.tables[0].columns)
] varchar(255),", c.columnname);
}strsql = strsql.trim() + ")";
using (system.data.sqlclient.sqlconnection sqlconn = new system.data.sqlclient.sqlconnection(connectionstring))
//用bcp匯入資料
using (system.data.sqlclient.sqlbulkcopy bcp = new system.data.sqlclient.sqlbulkcopy(connectionstring))
}catch (exception ex)
}
//進度顯示
private void bcp_sqlrowscopied(object sender, system.data.sqlclient.sqlrowscopiedeventargs e)
///
/// 獲取excel的表名
///
/// excel檔案
/// 資料表
private static datatable getexceltablename(string p_excelfile)
return null;
}catch
}private static void killallprocess() // 殺掉所有winword.exe程序
}catch
finally}}
}private void barbuttonitem停止匯入_itemclick(object sender, devexpress.xtrabars.itemclickeventargs e)
將excel表的資料匯入
import react from react import xlsx from xlsx class list extends react.component file.target 通過filereader物件讀取檔案 const filereader new filereader filere...
快速匯入Excel
using system using system.collections.generic using system.text using system.data.oledb using system.data.sqlclient using system.data using system.win...
將excel 檔案匯入access資料表
dim conn asnew oledbconnection my.settings.connstr datawarehouse.mdb dimcomm asoledbcommand conn.createcommand comm.commandtext insert into tablename ...