從Excel讀取第一個sheet的數據到dataset中 ,將dataset中的數據寫入第二個sheet
|
#region Excel----Access
#region GetDataFromExcel
//string strCon = @" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = E:/Documents and Settings/Administrator/桌面/Completeness_Xueyp_20090212.xls;Extended Properties=Excel 8.0";
//OleDbConnection myConn = new OleDbConnection(strCon);
//string strCom = " SELECT * FROM [Sheet3$] ";
//myConn.Open();
//OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
//DataSet myDataSet = new DataSet();
//myCommand.Fill(myDataSet, "[Sheet3$]");
//myConn.Close();
#endregion
#region Access----Excel
string sql = @"insert into TBL_ShortCutAccount select * from[Excel 8.0;
database=E:/Documents and Settings/Administrator/桌面/Completeness_Xueyp_20090212.xls].[Sheet2$]";
string strCon = @" Provider = Microsoft.Jet.OLEDB.4.0 ;
Data Source = E:/Documents and Settings/Administrator/桌面/AllDb/一般服務業/一般服務業.ekj;";
OleDbConnection myConn = new OleDbConnection(strCon);
myConn.Open();
OleDbCommand comm = new OleDbCommand(sql, myConn);
int val = comm.ExecuteNonQuery();
if (val > 0)
{
MessageBox.Show("數據導入成功!", "數據導入", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
myConn.Close();
#endregion
這個是Access的。其他的數據庫一樣,不過MS-SQL好像比這個還簡單點。。網上這個很多