HI GUYS,NOW I WILL SHARE A LITTLE CODES FOR RETRIEVING DATA FROM NOTEPAD INTO YOUR DATAGRIVIEW WITHOUT SQL DATABASE,THE NOTEPAD IS THE DATABASE.
YOU NEED TO ADD IN YOUR FORM THE TOOLS BELOW:
3 TEXTBOX
3 LABEL
2 BUTTON
CODES:
Imports System.Text
Imports System.Data.DataColumn
Imports System.IO.DirectoryInfo
'Imports VB_NOTEPAD_DATABSE
Imports Microsoft.Win32
Imports System.StringComparer
Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Threading
Public Class Form1
Private Sub ReadFile()
On Error Resume Next
Using sr As StreamReader = File.OpenText("DATABASE.txt")
Dim strLineIn As String
Dim strSplit() As String
DataGridView1.Rows.Clear()
Do While sr.Peek <> -1
strLineIn = sr.ReadLine
strSplit = strLineIn.Split(";")
DataGridView1.Rows.Add(strSplit(0), strSplit(1), strSplit(2))
Loop
sr.Close()
End Using
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ReadFile()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
On Error Resume Next
Dim temp As Integer = 0
For i As Integer = 0 To DataGridView1.RowCount - 1
For j As Integer = 0 To DataGridView1.ColumnCount - 1
If DataGridView1.Rows(i).Cells(j).Value.ToString = txtname.Text Then
DataGridView1.CurrentCell = DataGridView1.Rows(i).Cells(j)
MsgBox("Item found")
temp = 1
End If
Next
Next
If temp = 0 Then
MsgBox("Item not found")
End If
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
On Error Resume Next
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
txtid.Text = row.Cells(0).Value.ToString()
txtname.Text = row.Cells(1).Value.ToString()
txtstat.Text = row.Cells(2).Value.ToString()
End If
End Sub
End Class
PLEASE DONT FORGET TO SUPPORT MY YOUTUBE CHANNEL BY SUBSCRIBE AND
SUPPORT MY WEBSITE BY CLICKING ANY ADVERTISE LINK HERE.
THANKS!
No comments:
Post a Comment