Teman-teman,
Mo nanya nih..
Aku lagi buat program untuk tarik data dari csv file ke access.
Program ini sudah jadi tapi aku mau nambahin data column dengan cara
diketik di textbox.
Jadi maksudnya begini :
Di dalam csv file ada data "QC, Hasil, Unit" sebanyak 10 set data yang
kemudian dipindah ke access menjadi 10 records.
Nah, aku ingin menambahkan kolom data lagi yaitu "Nama" dimana data ini
aku akan ketik di textbox dan ikut dipindah ke access sesuai
dengan jumlah data yang ada di csv files. Pada contoh diatas ada 10
records.
Karena data di csv files belum ada data "Nama" dan aku harus entry manual.
Begitu juga untuk data "Bulan" dan "Tahun" yang diambil dari bulan dan
tahun yang ada dikomputer.
Logikanya bagaimana ya ?
ini contoh scriptnya..
Module Module1
Dim con As New OleDbConnection
Dim strProvier As String
Sub Main()
Dim strProvier = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=db1.mdb"
Dim con As New OleDbConnection(strProvier)
Dim cmd As New OleDbCommand()
Dim effectedRow As Integer
Dim lineCounter As Integer
con.Open()
If (con.State.ToString() = "Open") Then
Console.WriteLine("Connected To Database")
Dim stReader As New StreamReader("data.csv")
Dim strRowData As String()
Do While stReader.Peek() >= 0
lineCounter = lineCounter + 1
strRowData = stReader.ReadLine().Split("|")
Try
cmd.CommandText = "INSERT INTO
Table1(Name,Assay,Result,Unit) VALUES ('" & strRowData(1) & "','" &
strRowData(6) & "','" & strRowData(7) & "','" & strRowData(8) & "')"
cmd.Connection = con
effectedRow = cmd.ExecuteNonQuery()
If (effectedRow = 0) Then
Console.WriteLine("Line: " & lineCounter & "
Error")
Else
Console.WriteLine("Line: " & lineCounter & "
Executed Successfully")
End If
Catch er As OleDbException
Console.WriteLine("Line: " & lineCounter & " Error: "
& er.Message)
End Try
Loop
stReader.Close()
con.Close()
Else
Console.WriteLine("Not Connected To Database")
End If
Console.ReadKey()
End Sub
End Module
jonathan
This communication may contain information that is legally proprietary,
confidential, or exempt from disclosure. If you are not the intended
recipient, please note that any dissemination, distribution, use or copying of
this communication is strictly prohibited. Anyone who receives this message in
error should notify the sender immediately by telephone +62-21-52961529 or by
return e-mail and delete it from his or her computer.