当前位置:网站首页>Excel data into database
Excel data into database
2022-06-13 06:35:00 【l8487】
protected void Button1_Click(object sender, EventArgs e)
{
Server.ScriptTimeout = 100;
string path = this.Server.MapPath("1.xls");
SqlConnection conn = new SqlConnection("Data Source=192.168.1.150;Initial Catalog=WebDiskDB;User ID=sa;Password=aypostlxj");
conn.Open();
//SqlBulkCopy Pour in the data
SqlBulkCopy bulkCopy = new SqlBulkCopy(conn);
bulkCopy.BulkCopyTimeout = 200;
bulkCopy.DestinationTableName = "dbo.ok2";
bulkCopy.WriteToServer(UploadExcelData(path, "Sheet1").Tables[0]);
bulkCopy.Close();
conn.Close();
}
public DataSet UploadExcelData(string FileName, string SheetName)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileName + ";Extended Properties=/"Excel 8.0;HDR=YES;IMEX=1/";";
OleDbConnection conn = new OleDbConnection(strConn);
string strExcel = "select * from [Sheet1$]";
OleDbDataAdapter XlsCommand = null;
DataSet ds = new DataSet();
try
{
conn.Open();
XlsCommand = new OleDbDataAdapter(strExcel, strConn);
XlsCommand.Fill(ds, "sheet1");
}
catch (Exception ex)
{
Response.Write(" error !:" + ex.Message.ToString());
}
finally
{
conn.Close();
conn.Dispose();
}
return ds;
}
边栏推荐
- [JS] array flattening
- Kotlin collaboration - flow+room database
- ADB shell content command debug database
- Basic knowledge of knowledge map
- Echart histogram: X-axis displays value, Y-axis displays category
- 机器学习笔记 - 监督学习备忘清单
- 端午安康,使用祝福话语生成词云吧
- Kotlin collaboration process +flow download case
- 【js】var、let、const
- [kernel] two methods of driver compilation: compiling into modules and compiling into the kernel (using miscellaneous device driver templates)
猜你喜欢

You should consider upgrading via

华为开发者认证与DevEco Studio编译器下载
![[SketchUp 2021] CAD file import and modeling in the sketch master (establish elevation model in the sketch master by using CAD drawings), and the sketch master exports 2D, 3D and elevation effects of](/img/de/d0620a43c47a06d815c21ecb41a117.png)
[SketchUp 2021] CAD file import and modeling in the sketch master (establish elevation model in the sketch master by using CAD drawings), and the sketch master exports 2D, 3D and elevation effects of
![[DP 01 backpack]](/img/be/1e5295684ead652eebfb72ab0be47a.jpg)
[DP 01 backpack]

Echart rectangular tree diagram: simple implementation of rectangular tree diagram

JS convert text to language for playback

1+1 > 2, share creators can help you achieve

Solutions to common problems in small program development

【虚拟机】 VMware虚拟机占用空间过大解决

Echart histogram: echart implements stacked histogram
随机推荐
JetPack - - - LifeCycle、ViewModel、LiveData
347. top k high frequency elements heap sort + bucket sort +map
Thread pool learning
Echart histogram: echart implements stacked histogram
Applet disable native top
MFS详解(六)——MFS Chunk Server服务器安装与配置
二分查找
端午安康,使用祝福话语生成词云吧
Win10 drqa installation
Learning records countless questions (JS)
IOError(Errors.E050.format(name=name))
【2022高考季】作为一个过来人想说的话
Kotlin collaboration - flow+room database
Error in downloading opencv from pip
SSM integration
Applet export (use) public function, public data
Relationship between fragment lifecycle and activity
Binary search
Solutions to common problems in small program development
[virtual machine] VMware virtual machine occupies too much space. Solution