Dear Sir,
I'm Trying to import dat files from datatable into datagridview with VB.NET.
Please Guide Me
Below Mycode :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'openFileDialog1.ShowDialog()
'TextBox1.Text = openFileDialog1.FileName
'BindData(TextBox1.Text)
dt.Columns.Add("ID", GetType(String))
dt.Columns.Add("DATE", GetType(String))
dt.Columns.Add("TIME", GetType(String))
dt.Columns.Add("FP", GetType(String))
dt.Columns.Add("IN/OUT", GetType(String))
dt.Columns.Add("OTHERS1", GetType(String))
dt.Columns.Add("OTHERS2", GetType(String))
Dim fName As String = ""
OpenFileDialog1.InitialDirectory = "D:\TestFile"
OpenFileDialog1.Filter = "Dat files(*.Dat)|*.Dat"
OpenFileDialog1.RestoreDirectory = True
If (OpenFileDialog1.ShowDialog() = DialogResult.OK) Then
fName = OpenFileDialog1.FileName
End If
Dim TextLine As String = ""
Dim SplitLine() As String
If System.IO.File.Exists(fName) = True Then
Dim objReader As New System.IO.StreamReader(fName, Encoding.Default)
Dim index As Integer = 0
Do While objReader.Peek() <> -1
If index > 0 Then
TextLine = objReader.ReadLine()
SplitLine = Split(TextLine, " "c)
dt.Rows.Add(SplitLine)
Else
TextLine = objReader.ReadLine()
End If
index = index + 1
Loop
DataGridView1.DataSource = dt
Else
MsgBox("File Does Not Exist")
End If
End Sub
Desired Result
for columns IN/OUT if the value is 0 then it means IN and if the value is 1 it means OUT
ID | DATE | TIME | FP | IN/OUT | OTHERS1 | OTHERS2 |
5010 |
2024-03-18 |
06:59:10 |
1 |
IN |
0 |
0 |
5014 |
2024-03-18 |
07:11:00 |
1 |
IN |
0 |
0 |
5014 |
2024-03-18 |
16:32:09 |
1 |
OUT |
0 |
0 |
5010 |
2024-03-18 |
16:33:19 |
1 |
OUT |
0 |
0 |
5010 |
2024-03-19 |
07:05:15 |
1 |
IN |
0 |
0 |
5014 |
2024-03-19 |
07:31:19 |
1 |
IN |
0 |
0 |
5014 |
2024-03-19 |
16:30:50 |
1 |
OUT |
0 |
0 |
5010 |
2024-03-19 |
16:31:12 |
1 |
OUT |
0 |
0 |