Import Data Dari Excell ke Grid
Berikut adalah cara untuk import data dari file CSV ke grid pada vb.net. Grid yang saya gunakan adalah GridControl dari DevExpress.
Dim strfilename As String = BEIFileLocation.EditValue
Dim tmpstream As StreamReader = File.OpenText(strfilename)
Dim strlines() As String
strlines = tmpstream.ReadToEnd().Split(Environment.NewLine)
For x = 1 To UBound(strlines) - 1
Dim _strRows() As String = Split(strlines(x).ToString, ";")
Dim _dr As DataRow
_dr = _ds.TmpTblKontak.NewRow
_dr.Item("isValid") = False
_dr.Item("IDCabang") = _strRows(0).ToString.Trim
_dr.Item("IDDept") = _strRows(1).ToString.Trim
_dr.Item("IDdivisi") = _strRows(2).ToString.Trim
_dr.Item("IDPosisi") = _strRows(3).ToString.Trim
_dr.Item("IDGol") = _strRows(4).ToString.Trim
_dr.Item("NIK") = _strRows(5).ToString.Trim
_dr.Item("NoKTP") = _strRows(6).ToString.Trim
_dr.Item("Nama") = _strRows(7).ToString.Trim
_dr.Item("HP") = _strRows(8).ToString.Trim
_dr.Item("TempatLahir") = _strRows(9).ToString.Trim
_dr.Item("TglLahir") = _strRows(10).ToString.Trim
_dr.Item("Alamat") = _strRows(11).ToString.Trim
_dr.Item("Kota") = _strRows(12).ToString.Trim
_dr.Item("Email") = _strRows(13).ToString.Trim
_dr.Item("Status") = _strRows(14).ToString.Trim
_ds.TmpTblKontak.Rows.Add(_dr)
Next
GridControl1.DataSource = _ds.TmpTblKontak
Labels:
DevExpress,
GridControl,
VB.NET
0 komentar:
Posting Komentar