0% found this document useful (0 votes)
26 views

New 2

The document describes a program for managing a lab inventory database. It connects to an Access database, defines methods for loading data, inserting, updating, deleting and searching records, and includes a user interface with text boxes and buttons to call these database methods.
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)
26 views

New 2

The document describes a program for managing a lab inventory database. It connects to an Access database, defines methods for loading data, inserting, updating, deleting and searching records, and includes a user interface with text boxes and buttons to call these database methods.
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/ 5

Imports System.Data.

OleDb
Public Class MainForm
Dim connection As String
Dim connstring As String
Dim command As String
Dim myconnection As OleDbConnection = New OleDbConnection
Dim ds As New OleDbDataAdapter
Dim con As New OleDbConnection
Dim dt As New DataTable
Dim dr As OleDbDataReader

Public Sub Conn()


connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Admin\
Documents\computer_information _system.accdb"
End Sub
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
If MessageBox.Show("Are you sure you want to exit?", "Exit ",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes
Then
Me.Close()
End If
End Sub

Public Sub Load_Data()


Conn()
connstring = connection
myconnection.ConnectionString = connstring
myconnection.Open()
ds = New OleDbDataAdapter("select * from lab_info", myconnection)
ds.Fill(dt)
DataGridView1.DataSource = dt.DefaultView
myconnection.Close()
End Sub

Private Sub ViewCars_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Load_Data()
End Sub

Private Sub Label7_Click(sender As Object, e As EventArgs) Handles label6.Click

End Sub

Private Sub Label5_Click(sender As Object, e As EventArgs) Handles label8.Click

End Sub

Private Sub Label4_Click(sender As Object, e As EventArgs) Handles


label11.Click

End Sub

Private Sub Label1_Click(sender As Object, e As EventArgs) Handles label1.Click

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
Conn()
connstring = connection
myconnection.ConnectionString = connstring
myconnection.Open()

If itemName.Text.Trim = "" Or itemModelNo.Text.Trim = "" Or


itemBrand.Text.Trim = "" Or Qty.Text.Trim = "" Or Des.Text.Trim = _
"" Or status.Text.Trim = "" Then
MessageBox.Show("All fields are required", "Input",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
Try
myconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Else

command = "Insert INTO lab_info ([item_name],[item_number],


[item_brandname],[Quantity],[Description],[Status],[Datee]) values ('" &
itemName.Text & _
"','" & itemModelNo.Text & "','" & itemBrand.Text & "','" &
Qty.Text & "','" & Des.Text & "','" & status.Text & "','" & datee.Text & "')"

Dim cmd As OleDbCommand = New OleDbCommand(command, myconnection)

cmd.Parameters.Add(New OleDbParameter("item_name", CType(itemName.Text,


String)))
cmd.Parameters.Add(New OleDbParameter("item_number",
CType(itemModelNo.Text, String)))
cmd.Parameters.Add(New OleDbParameter("item_brandname",
CType(itemBrand.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Quantity", CType(Qty.Text,
String)))
cmd.Parameters.Add(New OleDbParameter("Description", CType(Des.Text,
String)))
cmd.Parameters.Add(New OleDbParameter("Status", CType(status.Text,
String)))
cmd.Parameters.Add(New OleDbParameter("Datee", CType(datee.Text,
String)))
MessageBox.Show("Successfully Added", "Added", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
myconnection.Close()
itemName.Clear()
itemModelNo.Clear()
itemBrand.Clear()
Qty.Clear()
Des.Clear()
status.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click
Conn()
connstring = connection
myconnection.ConnectionString = connstring
myconnection.Open()

If itemModelNo.Text = "" Then


MessageBox.Show("Please enter the Item Number ...", "Empty",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
Try
myconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
Dim cmd As New OleDbCommand("Update from lab_info where item_number =
'" & itemModelNo.Text & "'", myconnection)
cmd.ExecuteNonQuery()
dr = cmd.ExecuteReader
If dr.Read Then
itemName.Text = dr("item_name")
itemModelNo.Text = dr("item_number")
itemBrand.Text = dr("item_brandname")
Qty.Text = dr("Quantity")
Des.Text = dr("Description")
status.Text = dr("Status")
datee.Text = dr("Datee")
End If
Try

myconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


Button4.Click
itemName.Clear()
itemModelNo.Clear()
itemBrand.Clear()
Qty.Clear()
Des.Clear()
status.Clear()
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles


Button5.Click

Conn()
connstring = connection
myconnection.ConnectionString = connstring
myconnection.Open()

If itemModelNo.Text = "" Then


MessageBox.Show("Please enter the Item Number ...", "Empty",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
Try
myconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
Dim cmd As New OleDbCommand("Select * from lab_info where item_number =
'" & itemModelNo.Text & "'", myconnection)
cmd.ExecuteNonQuery()
dr = cmd.ExecuteReader
If dr.Read Then
itemName.Text = dr("item_name")
itemModelNo.Text = dr("item_number")
itemBrand.Text = dr("item_brandname")
Qty.Text = dr("Quantity")
Des.Text = dr("Description")
status.Text = dr("Status")
datee.Text = dr("Datee")
End If
Try

myconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
Conn()
connstring = connection
myconnection.ConnectionString = connstring
myconnection.Open()

If itemModelNo.Text = "" Then


MessageBox.Show("Please enter the Item Number ...", "Empty",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
Try
myconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
Dim cmd As New OleDbCommand("Delete * from lab_info where item_number =
'" & itemModelNo.Text & "'", myconnection)
cmd.ExecuteNonQuery()
dr = cmd.ExecuteReader
If dr.Read Then
itemName.Text = dr("item_name")
itemModelNo.Text = dr("item_number")
itemBrand.Text = dr("item_brandname")
Qty.Text = dr("Quantity")
Des.Text = dr("Description")
status.Text = dr("Status")
datee.Text = dr("Datee")
End If
Try

myconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub

You might also like