0% found this document useful (0 votes)
44 views4 pages

Sasasas

This document contains code for a form application that allows users to perform CRUD (create, read, update, delete) operations on a database table using a .NET interface. The form contains text boxes and a datagridview to display records. Methods are defined to save, load, edit, delete, search, and clear records by executing SQL commands on an OleDbConnection to a Microsoft Jet database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

Sasasas

This document contains code for a form application that allows users to perform CRUD (create, read, update, delete) operations on a database table using a .NET interface. The form contains text boxes and a datagridview to display records. Methods are defined to save, load, edit, delete, search, and clear records by executing SQL commands on an OleDbConnection to a Microsoft Jet database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Imports System.Data.

OleDb
Imports System.IO
Public Class Form1

Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="


& Application.StartupPath & "\CURD.mdb")
Dim dr As OleDbDataReader
Dim i As Integer

Sub save()
Try
conn.Open()
If MsgBox("want to record?", vbQuestion + vbYesNo) = vbYes Then
Dim cmd As New OleDbCommand(" Insert into CURD
(ID,FirstName,MiddleName,LastName,Age,Birthdate) values
(@ID,@FirstName,@MiddleName,@LastName,@Age,@Birthdate)", conn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@ID", TextBox1.Text)
cmd.Parameters.AddWithValue("@FirstName", TextBox2.Text)
cmd.Parameters.AddWithValue("@MiddleName", TextBox3.Text)
cmd.Parameters.AddWithValue("@LastName", TextBox4.Text)
cmd.Parameters.AddWithValue("@Age", TextBox5.Text)
cmd.Parameters.AddWithValue("@Birthdate", DateTimePicker1.Text)
i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Record Save Successfully!", vbInformation)
Else
MsgBox("Failed!", vbCritical)
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
LoadingDataGridView()
clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
save()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
loadingDataGridView()
End Sub
Sub LoadingDataGridView()
Try
DataGridView1.Rows.Clear()
conn.Open()
Dim cmd As New OleDbCommand("Select * from CURD", conn)
dr = cmd.ExecuteReader()
While dr.Read
DataGridView1.Rows.Add(dr.Item("ID"), dr.Item("FirstName"),
dr.Item("MiddleName"), dr.Item("LastName"), dr.Item("Age"), dr.Item("Birthdate"))

End While
Catch ex As Exception
MsgBox(ex.Message)

End Try
conn.close()
End Sub

Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox5.TextChanged

End Sub
Sub clear()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextSearch.Clear()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
clear()
End Sub
Sub delete()

Try
conn.Open()
If MsgBox("want to Delete?", vbQuestion + vbYesNo) = vbYes Then
Dim cmd As New OleDbCommand(" Delete from CURD where ID = @ID",
conn)
cmd.Parameters.Clear()

cmd.Parameters.AddWithValue("@ID", TextBox1.Text)
i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Record Delete Successfully!", vbInformation)
Else
MsgBox("Failed!", vbCritical)
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
LoadingDataGridView()
clear()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
delete()

End Sub

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value
TextBox2.Text = DataGridView1.CurrentRow.Cells(1).Value
TextBox3.Text = DataGridView1.CurrentRow.Cells(2).Value
TextBox4.Text = DataGridView1.CurrentRow.Cells(3).Value
TextBox5.Text = DataGridView1.CurrentRow.Cells(4).Value
DateTimePicker1.Text = DataGridView1.CurrentRow.Cells(5).Value

End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal


e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentClick

End Sub
Sub edit()
Try
conn.Open()
If MsgBox("want to record?", vbQuestion + vbYesNo) = vbYes Then
Dim cmd As New OleDbCommand(" UPDATE CURD SET ID= '" &
TextBox1.Text & "',FirstName = '" & TextBox2.Text & "',MiddleName = '" &
TextBox3.Text & "',Lastname = '" & TextBox4.Text & "', Age = '" & TextBox5.Text &
"', Birthdate = '" & DateTimePicker1.Text & "' WHERE ID = " & TextBox1.Text & "",
conn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@ID", TextBox1.Text)
cmd.Parameters.AddWithValue("@FirstName", TextBox2.Text)
cmd.Parameters.AddWithValue("@MiddleName", TextBox3.Text)
cmd.Parameters.AddWithValue("@LastName", TextBox4.Text)
cmd.Parameters.AddWithValue("@Age", TextBox5.Text)
cmd.Parameters.AddWithValue("@Birthdate", DateTimePicker1.Text)

i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Record Update Successfully!", vbInformation)
Else
MsgBox("Failed!", vbCritical)
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
LoadingDataGridView()
clear()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
edit()

End Sub
Sub search()
Try
DataGridView1.Rows.Clear()
conn.Open()
Dim cmd As New OleDbCommand("Select * from CURD WHERE ID like '%" &
TextSearch.Text & "%' or FirstName like '%" & TextSearch.Text & "%' or MiddleName
like '%" & TextSearch.Text & "%' or LastName like '%" & TextSearch.Text & "%'or Age
like '%" & TextSearch.Text & "%'or Birthdate like '%" & TextSearch.Text & "%' ",
conn)
dr = cmd.ExecuteReader()
While dr.Read
DataGridView1.Rows.Add(dr.Item("ID"), dr.Item("FirstName"),
dr.Item("MiddleName"), dr.Item("LastName"), dr.Item("Age"), dr.Item("Birthdate"))

End While

Catch ex As Exception
MsgBox(ex.Message)

End Try
conn.Close()
End Sub
Private Sub TextSearch_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextSearch.TextChanged
search()
End Sub
End Class

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy