Dim cn As New Data.OleDb.OleDbConnection Dim da As Data.OleDb.OleDbDataAdapter Dim dt As New DataTable Dim sqlstr As String Dim oComm As SqlCommand cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " & Server.MapPath("檔名.XLS") & "; Extended Properties=Excel 8.0;" For i As Integer = 1 To 100 'excel內有100筆資料 cn.Open() da = New OleDb.OleDbDataAdapter("select * from [Data$]", cn) 'Data=>"Booksheet" da.Fill(dt) sqlstr = sqlstr + "INSERT INTO SPC_Table (零件件號) VALUES (dt.Rows(i + 4).Item(1)" 'excel內每筆資料為Row Dim ds As New DataSet SqlConnection1.Open() oComm = New SqlCommand(sqlstr, SqlConnection1) oComm.ExecuteNonQuery() SqlConnection1.Close() cn.Close() Next
2009年9月21日 星期一
ASP.NET 編輯 excel 檔
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言