Inherits System.Windows.Forms.Form Dim DS1 As New System.data.dataset Dim Ds2 As New System.Data.DataSet
Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim MyCommand As System.Data.OleDb.OleDbDataAdapter Dim MyConnection As System.Data.OleDb.OleDbConnection
MyConnection = new system.data.oledb.oledbconnection (_ "provider = microsoft.jet.Oledb.4.0;" & _ "data source = e: /book1.xls;" & _ "extended Properties = Excel 8.0;") ' Select the data from sheet1 of the workbook. Mycomb = new system.data.oledb.oledbdataadapter (_ "SELECT * from [Sheet1 $]", myconnection) or DS1.ReadXML ("c: /abcd.xml")
MyCommand.Fill (DS1, "Handle") DataGrid1.datasource = DS1 myconnection.close ()
End Sub
Private Sub Button2_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try Dim j As Integer Dim person_id, information_id, handle As String Dim handle_time As System.DateTime 'If Me.SqlConnection1.Close () Then me.sqlconnection1.open () 'end if for j = 1 to ds1.tables ("Handle"). Rows.count - 1
Me.SqlDataAdapter1.insertCommand.Parameters ("@ person_id"). Value = DS1.Tables ("Handle"). Rows (j) .Item (0) me.sqldataadapter1.insertCommand.Parameters ("@ information_id"). Value = DS1.Tables ("Handle"). Rows (j) .Item (1) 'me.sqldataadapter1.insertcommand.Parameters ("@ Handle"). Value = ds1.tables ("Handle"). Rows (j) .Itemm (2) Me.SqldataAdapter1.insertCommand.Parameters ("@ Handle_time"). Value = cdate ("Handle"). Rows (j) .Item (3)) Me.SqlDataAdapter1.insertCommand.executenonQuery () Next 'MessageBox.Show (SqlDataAdapter1.insertcommand.commandtext) me.sqlconnection1.close () catch exception messageBox.show (ex.Message) End Sub
An example, the principle is to first read the data of the Excel or XML file through the DataSet to the DataGrid, and then save it to the database.