Hi kana250688,
Refer below code.
Namespaces
C#
using System.Data;
using System.IO;
VB.Net
Imports System.Data
Imports System.IO
Code
C#
protected void ReadDat(object sender, EventArgs e)
{
string[] lines = File.ReadAllLines("E:\\Files\\1_attlog.dat");
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("DATE", typeof(string));
dt.Columns.Add("TIME", typeof(string));
dt.Columns.Add("FP", typeof(string));
dt.Columns.Add("IN/OUT", typeof(string));
dt.Columns.Add("OTHERS1", typeof(string));
dt.Columns.Add("OTHERS2", typeof(string));
for (int i = 0; i < lines.Length; i++)
{
if (!string.IsNullOrEmpty(lines[i].Trim()))
{
string[] data = lines[i].Trim().Split('\t');
dt.Rows.Add(data[0], data[1].ToString().Split(' ')[0], data[1].ToString().Split(' ')[1], data[2], data[3].ToString() == "0" ? "IN" : "OUT", data[4], data[5]);
}
}
// Use the DataTable to populate the DataGridView.
DataGridView1.DataSource = dt;
}
VB.Net
Protected Sub ReadDat(ByVal sender As Object, ByVal e As EventArgs)
Dim lines As String() = File.ReadAllLines("E:\\Files\\1_attlog.dat")
Dim dt As DataTable = New DataTable()
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))
For i As Integer = 0 To lines.Length - 1
If Not String.IsNullOrEmpty(lines(i).Trim()) Then
Dim data As String() = lines(i).Trim().Split(vbTab)
dt.Rows.Add(data(0), data(1).ToString().Split(" "c)(0), data(1).ToString().Split(" "c)(1), data(2), If(data(3).ToString() = "0", "IN", "OUT"), data(4), data(5))
End If
Next
' Use the DataTable to populate the DataGridView.
DataGridView1.DataSource = dt
End Sub
Screenshot
For populating DataGridView refer Bind (Fill) DataGridView in Windows Forms (WinForms) Application in C# and VB.Net.