C#?и?Ч??excel????sqlserver?????
???????????? ???????[ 2014/8/28 10:56:37 ] ????????.NET C# ??????? ???????
??????oledb?????excel???????????sqlserver?У?????????????????sql??????????????????????Ч????£?????????? bcp?????System.Data.SqlClient.SqlBulkCopy ?????????????????????????????????????????6??????????sheet??????????????????????????????????????????10?????????????????????????4.5??
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender?? EventArgs e)
{
//???????excel?е?sheet1????sqlserver??
string connString = "server=localhost;uid=sa;pwd=sqlgis;database=master";
System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
if (fd.ShowDialog() == DialogResult.OK)
{
TransferData(fd.FileName?? "sheet1"?? connString);
}
}
public void TransferData(string excelFile?? string sheetName?? string connectionString)
{
DataSet ds = new DataSet();
try
{
//??????????
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelFile + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
strExcel = string.Format("select * from [{0}$]"?? sheetName);
myCommand = new OleDbDataAdapter(strExcel?? strConn);
myCommand.Fill(ds?? sheetName);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11