导入到project_task_effort和project_task_effort_details表中,数据库连接连接名为MetricsConn
ç¨OLEDBè¿è¡Excelæ件æ°æ®è¯»å并è¿DataSetæ°æ®éå
¶å ç¹éè¦æ³¨æï¼
1.è¿æ¥å符串åæ°IMEX å¼ï¼
0 is Export mode
1 is Import mode
2 is Linked mode (full update capabilities)
IMEX3å¼ï¼IMEX=2 EXCELææ¡£åå«å符åæ°ååæ¯ç¬¬Cå3å¼2æ°å¼å 1231å符å ABCå¯¼å ¥
页é¢æ¥éåºæ¾ç¤ºæ°å¼å123å符åABCååç°ç©ºå¼IMEX=1è¿°æ åµååºç¡®åç° 123 ABC.
2.åæ°HDRå¼ï¼
HDR=Yes代表第è¡æ é¢åæ°æ®ä½¿ç¨ ç¨HDR=NOå表示第è¡æ é¢åæ°æ®ä½¿ç¨ç³»ç»é»è®¤YES
3.åæ°Excel 8.0
äºExcel 97çæ¬é½ç¨Excel 8.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#region è·åexcel dataset ,å³åexcel_ds
string excelFilePath = openFileDialog1.FileName;//å¼¹æ件éåçªå£è·åEXCELæ件路å¾
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFilePath + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
OleDbConnection Oleconn = new OleDbConnection(strConn);
string strExcel = "";
OleDbDataAdapter excelCommand = null;
DataSet excel_ds = new DataSet();
strExcel = "select * from [sheet1$]";
try
{
Oleconn.Open();
excelCommand = new OleDbDataAdapter(strExcel,Oleconn);
excelCommand.Fill(excel_ds,"exdtSource");//dataset
}
catch (System.Exception ex)
{
MessageBox.Show("å¯¼å ¥éï¼" + ex, "é误信æ¯");
}
finally
{
Oleconn.Close();
Oleconn.Dispose();
}
#endregion
1.è¿æ¥å符串åæ°IMEX å¼ï¼
0 is Export mode
1 is Import mode
2 is Linked mode (full update capabilities)
IMEX3å¼ï¼IMEX=2 EXCELææ¡£åå«å符åæ°ååæ¯ç¬¬Cå3å¼2æ°å¼å 1231å符å ABCå¯¼å ¥
页é¢æ¥éåºæ¾ç¤ºæ°å¼å123å符åABCååç°ç©ºå¼IMEX=1è¿°æ åµååºç¡®åç° 123 ABC.
2.åæ°HDRå¼ï¼
HDR=Yes代表第è¡æ é¢åæ°æ®ä½¿ç¨ ç¨HDR=NOå表示第è¡æ é¢åæ°æ®ä½¿ç¨ç³»ç»é»è®¤YES
3.åæ°Excel 8.0
äºExcel 97çæ¬é½ç¨Excel 8.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#region è·åexcel dataset ,å³åexcel_ds
string excelFilePath = openFileDialog1.FileName;//å¼¹æ件éåçªå£è·åEXCELæ件路å¾
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFilePath + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
OleDbConnection Oleconn = new OleDbConnection(strConn);
string strExcel = "";
OleDbDataAdapter excelCommand = null;
DataSet excel_ds = new DataSet();
strExcel = "select * from [sheet1$]";
try
{
Oleconn.Open();
excelCommand = new OleDbDataAdapter(strExcel,Oleconn);
excelCommand.Fill(excel_ds,"exdtSource");//dataset
}
catch (System.Exception ex)
{
MessageBox.Show("å¯¼å ¥éï¼" + ex, "é误信æ¯");
}
finally
{
Oleconn.Close();
Oleconn.Dispose();
}
#endregion
温馨提示:答案为网友推荐,仅供参考