当前位置:网站首页>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;
}
边栏推荐
- [MySQL] basic knowledge review
- Using async await in applets
- JNI exception handling
- Uniapp secondary encapsulates uview components, and the parent component controls display and hiding
- Notifyitemchanged flash back
- Uniapp (upload local pictures, preview pictures, convert Base64 format, upload audio files)
- Wechat applet custom tabbar (session customer service) vant
- 欧姆龙平替国产大货—JY-V640半导体晶元盒读写器
- Binary search
- App performance test: (I) startup time
猜你喜欢

【新手上路常见问答】一步一步理解程序设计

MFS详解(七)——MFS客户端与web监控安装配置

Relationship between fragment lifecycle and activity

Echart histogram: X-axis displays value, Y-axis displays category

华为开发者认证与DevEco Studio编译器下载

MFS details (VII) -- MFS client and web monitoring installation configuration

杨辉三角形详解

Kotlin collaboration -- context and exception handling

Vector control of Brushless DC motor (4): sensorless control based on sliding mode observer

c语言对文件相关的处理和应用
随机推荐
【新手上路常见问答】关于技术管理
[solution] camunda deployment process should point to a running platform rest API
Solution: vscode open file will always overwrite the last opened label
Cross process two-way communication using messenger
Wechat applet (pull-down refresh data) novice to
SSM integration
Differences among concurrent, parallel, serial, synchronous and asynchronous
Detailed explanation of the player startup process of ijkplayer code walk through
Usegeneratedkeys=true configuration
无刷直流电机矢量控制(四):基于滑模观测器的无传感器控制
Recommend a capacity expansion tool to completely solve the problem of insufficient disk space in Disk C and other disks
Solutions to common problems in small program development
Kotlin collaboration channel
Scrcpy source code walk 2 how to connect a client to a mobile server
楊輝三角形詳解
MFS详解(五)——MFS元数据日志服务器安装与配置
MFS details (vii) - - MFS client and Web Monitoring installation configuration
MFS details (VII) -- MFS client and web monitoring installation configuration
Comprehensive overview of ijkplayer contour features for ijkplayer code walk through
Scrcpy source code walk 3 what happened between socket and screen refresh