--> Skip to main content
Pelajar Koding

follow us

Vb6 Ms. Access: Import Dari Csv File - Part 3

*.csv" CommonDialog1.ShowOpen Text1.Text = CommonDialog1.FileName If Me.Text1.Text = "" Then Exit Sub strFileName = Text1.Text ' mengambil isi file fnum = FreeFile Open strFileName For Input As fnum strFileValue = Input$(LOF(fnum), #fnum) Close fnum ' memecah baris ke variable lines. lines = Split(strFileValue, vbCrLf) ' jumlah baris num_rows = UBound(lines) 'header/nama kolom one_line = Split(lines(0), Me.Combo1.Text) num_cols = UBound(one_line) Data_Temp one_line ' input nilai ke recordset For r = 1 To num_rows - 1     rsTemp.AddNew     one_line = Split(lines(r), Combo1.Text)     For c = 0 To num_cols         rsTemp.Fields(c).Value = one_line(c)     Next     rsTemp.Update Next rsTemp.MoveFirst Command2.Enabled = True End Sub Sub RunQuery(sSQL As String ) Dim cmd As New ADODB.Command Set cmd = New ADODB.Command   With cmd     .ActiveConnection = strConn     .CommandType = adCmdText     .CommandText = sSQL     .Execute   End With End Sub   Private Sub Command2_Click() On Error GoTo errHandler rsTemp.MoveFirst For i = 0 To rsTemp.RecordCount - 1     RunQuery "INSERT INTO category " & _              "(categorycode, categoryname) VALUES " & _              "('" & rsTemp.Fields(0).Value & "', " & _              "'" & rsTemp.Fields(1).Value & "')"     rsTemp.MoveNext Next rsTemp.MoveFirst MsgBox "Proses Import Selesai" Load_Data Exit Sub errHandler: MsgBox "Error on Import: " & Err.Description End Sub Click here if you like this article.
Sumber http://rani-irsan.blogspot.com

You Might Also Like:

Comment Policy: Silahkan tuliskan komentar Anda yang sesuai dengan topik postingan halaman ini. Komentar yang berisi tautan tidak akan ditampilkan sebelum disetujui.
Buka Komentar