1
Inherits
System.Windows.Forms.Form
2 Dim DS1 As New System.Data.DataSet
3 Dim DS2 As New System.Data.DataSet
4
5 Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
6 Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
7 Dim MyConnection As System.Data.OleDb.OleDbConnection
8
9 MyConnection = New System.Data.OleDb.OleDbConnection( _
10 " provider=Microsoft.Jet.OLEDB.4.0; " & _
11 " data source=e:\BOOK1.XLS; " & _
12 " Extended Properties=Excel 8.0; " )
13 ' Select the data from Sheet1 of the workbook.
14 MyCommand = New System.Data.OleDb.OleDbDataAdapter( _
15 " select * from [Sheet1$] " , MyConnection)
16 ' 或者是DS1.ReadXml("c:\abcd.xml")
17
18 MyCommand.Fill(DS1, " handle " )
19 DataGrid1.DataSource = DS1
20 MyConnection.Close()
21
22 End Sub
23
24 Private Sub Button2_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
25 Try
26 Dim j As Integer
27 Dim person_id, information_id, handle As String
28 Dim handle_time As System.DateTime
29 ' If Me.SqlConnection1.Close() Then
30 Me .SqlConnection1.Open()
31 ' End If
32 For j = 1 To DS1.Tables( " handle " ).Rows.Count - 1
33
34 Me .SqlDataAdapter1.InsertCommand.Parameters( " @person_id " ).Value = DS1.Tables( " handle " ).Rows(j).Item( 0 )
35 Me .SqlDataAdapter1.InsertCommand.Parameters( " @information_id " ).Value = DS1.Tables( " handle " ).Rows(j).Item( 1 )
36 ' Me.SqlDataAdapter1.InsertCommand.Parameters("@handle").Value = DS1.Tables("handle").Rows(j).Item(2)
37 Me .SqlDataAdapter1.InsertCommand.Parameters( " @handle_time " ).Value = CDate (DS1.Tables( " handle " ).Rows(j).Item( 3 ))
38 Me .SqlDataAdapter1.InsertCommand.ExecuteNonQuery()
39 Next
40
41 ' MessageBox.Show(SqlDataAdapter1.InsertCommand.CommandText)
42 Me .SqlConnection1.Close()
43 Catch ex As Exception
44 MessageBox.Show(ex.Message)
45 End Try
46 End Sub
47
2 Dim DS1 As New System.Data.DataSet
3 Dim DS2 As New System.Data.DataSet
4
5 Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
6 Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
7 Dim MyConnection As System.Data.OleDb.OleDbConnection
8
9 MyConnection = New System.Data.OleDb.OleDbConnection( _
10 " provider=Microsoft.Jet.OLEDB.4.0; " & _
11 " data source=e:\BOOK1.XLS; " & _
12 " Extended Properties=Excel 8.0; " )
13 ' Select the data from Sheet1 of the workbook.
14 MyCommand = New System.Data.OleDb.OleDbDataAdapter( _
15 " select * from [Sheet1$] " , MyConnection)
16 ' 或者是DS1.ReadXml("c:\abcd.xml")
17
18 MyCommand.Fill(DS1, " handle " )
19 DataGrid1.DataSource = DS1
20 MyConnection.Close()
21
22 End Sub
23
24 Private Sub Button2_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
25 Try
26 Dim j As Integer
27 Dim person_id, information_id, handle As String
28 Dim handle_time As System.DateTime
29 ' If Me.SqlConnection1.Close() Then
30 Me .SqlConnection1.Open()
31 ' End If
32 For j = 1 To DS1.Tables( " handle " ).Rows.Count - 1
33
34 Me .SqlDataAdapter1.InsertCommand.Parameters( " @person_id " ).Value = DS1.Tables( " handle " ).Rows(j).Item( 0 )
35 Me .SqlDataAdapter1.InsertCommand.Parameters( " @information_id " ).Value = DS1.Tables( " handle " ).Rows(j).Item( 1 )
36 ' Me.SqlDataAdapter1.InsertCommand.Parameters("@handle").Value = DS1.Tables("handle").Rows(j).Item(2)
37 Me .SqlDataAdapter1.InsertCommand.Parameters( " @handle_time " ).Value = CDate (DS1.Tables( " handle " ).Rows(j).Item( 3 ))
38 Me .SqlDataAdapter1.InsertCommand.ExecuteNonQuery()
39 Next
40
41 ' MessageBox.Show(SqlDataAdapter1.InsertCommand.CommandText)
42 Me .SqlConnection1.Close()
43 Catch ex As Exception
44 MessageBox.Show(ex.Message)
45 End Try
46 End Sub
47