Import Excel and XML into the database

Source: Internet
Author: User
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 Button#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 = Microsoft 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 ' Or 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  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.