Wow!!! ang galing!!! gs2 ko 2... sana mrmi aqng matutunan d2.. tpos n kc kmi sa .net.. pero gs2 q tlg 2ng pagaralan.. gnito po ung tinuro samin sa file maintenance,,
Imports System.Data.OleDb
Public Class Form1
Dim Conn As OleDbConnection
Dim Comm As OleDbCommand
Dim OleA As OleDbDataAdapter
Dim Ds As New DataSet
Dim SQLStr As String
Dim Drow As DataRow
Dim bool As Integer
Dim ID As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyConnect()
DisableTxtBox()
PopulateDataGrid()
btnSave.Enabled = False
txtStno.Enabled = True
End Sub
Private Sub MyConnect()
Try
Conn = New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Application.StartupPath & "/Student.mdb")
Conn.Open()
Catch ex As Exception
MessageBox.Show (ex.Message ,"Connection Error",MessageBoxButtons.OK)
End Try
End Sub
Private Sub PopulateDataGrid()
MyConnect()
SQLStr = "SELECT * FROM tblStud ORDER BY ID"
Comm = New OleDbCommand(SQLStr, Conn)
OleA = New OleDbDataAdapter(Comm)
Ds.Clear()
OleA.Fill(Ds, "tblStud")
DataGridView1.DataSource = Ds
DataGridView1.DataMember = "tblStud"
Conn.Close()
End Sub
Private Sub DisableTxtBox()
txtFirst.Enabled = False
txtLast.Enabled = False
txtSection.Enabled = False
txtStno.Enabled = False
End Sub
Private Sub EnableTxtBox()
txtFirst.Enabled = True
txtLast.Enabled = True
txtSection.Enabled = True
txtStno.Enabled = True
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
EnableTxtBox()
btnAdd.Enabled = False
btnDel.Enabled = False
btnEdit.Enabled = False
btnSave.Enabled = True
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
EnableTxtBox()
Try
MyConnect()
SQLStr = "INSERT INTO tblStud (Stno, LName, FName, Sect) VALUES ('" & txtStno.Text & "', '" & txtLast.Text & "', '" & txtFirst.Text & "' , '" & txtSection.Text & "' )"
Comm = New OleDbCommand(SQLStr, Conn)
Comm.ExecuteNonQuery()
MessageBox.Show("Record Save.")
PopulateDataGrid()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
txtFirst.Clear()
txtLast.Clear()
txtSection.Clear()
txtStno.Clear()
btnAdd.Enabled = True
btnSave.Enabled = False
btnDel.Enabled = True
btnQuit.Enabled = True
DisableTxtBox()
txtStno.Enabled = True
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
Try
If btnEdit.Text = "." Then
If (SearchMe()) Then
EnableTxtBox()
btnEdit.Text = ","
btnSave.Enabled = False
End If
Else
'UpDate ******************************************
MyConnect()
SQLStr = "UPDATE tblStud SET Stno='" & txtStno.Text & "',LName='" & txtLast.Text & "',FName='" & txtFirst.Text & "',Sect='" & txtSection.Text & "' WHERE ID=" & ID & ""
Comm = New OleDbCommand(SQLStr, Conn)
Comm.ExecuteNonQuery()
MessageBox.Show("Record Updated!.....")
PopulateDataGrid()
DisableTxtBox()
btnSave.Enabled = False
btnEdit.Text = ""
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function SearchMe() As Boolean
Dim StrSearch As String = InputBox("Enter Student Number", "Record Search", "")
If (StrSearch.Length > 0) Then
bool = 1
Else
bool = 0
End If
MyConnect()
SQLStr = "SELECT * FROM tblStud WHERE Stno ='" & StrSearch & "'"
Comm = New OleDbCommand(SQLStr, Conn)
OleA = New OleDbDataAdapter(Comm)
Ds.Clear()
OleA.Fill(Ds, "tblStud")
If Ds.Tables("tblStud").Rows.Count > 0 Then
Drow = Ds.Tables("tblStud").Rows(0)
ID = Drow("ID")
txtFirst.Text = Drow("FName")
txtLast.Text = Drow("LName")
txtSection.Text = Drow("Sect")
txtStno.Text = Drow("Stno")
PopulateDataGrid()
SearchMe = True
Else
PopulateDataGrid()
SearchMe = False
End If
End Function
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
MyConnect()
SQLStr = "SELECT * FROM tblStud WHERE Stno = '" & txtStno.Text & "'"
Comm = New OleDbCommand(SQLStr, Conn)
OleA = New OleDbDataAdapter(Comm)
Ds.Clear()
OleA.Fill(Ds, "tblStud")
If Ds.Tables("tblStud").Rows.Count > 0 Then
Drow = Ds.Tables("tblStud").Rows(0)
ID = Drow("ID")
txtFirst.Text = Drow("FName")
txtLast.Text = Drow("LName")
txtSection.Text = Drow("Sect")
txtStno.Text = Drow("Stno")
PopulateDataGrid()
Else
MessageBox.Show("Sorry! Student Number didn't match.")
End If
End Sub
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
Try
If (MessageBox.Show("Delete This Record", "Deleting of Record", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes) Then
MyConnect()
SQLStr = "DELETE FROM tblStud WHERE Stno='" & txtStno.Text & "'"
Comm = New OleDbCommand(SQLStr, Conn)
Comm.ExecuteNonQuery()
MessageBox.Show("Record Deleted!.....")
PopulateDataGrid()
Else
Exit Sub
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
If bool = 1 Then
MessageBox.Show("Record Does Not Exist!.....")
End If
End Sub
End Class
Imports System.Data.OleDb
Public Class Form2
Dim Conn As OleDbConnection
Dim Comm As OleDbCommand
Dim OleA As OleDbDataAdapter
Dim Ds As New DataSet
Dim SQLStr As String
Dim Drow As DataRow
Dim bool As Integer
Dim ID As Integer
Dim SW As Integer
Private Sub MyConnectS()
Try
Conn = New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Application.StartupPath & "/Student.mdb")
Conn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK)
End Try
End Sub
Private Sub PopulateDataGridS()
MyConnectS()
SQLStr = "SELECT * FROM tblStud ORDER BY ID"
Comm = New OleDbCommand(SQLStr, Conn)
OleA = New OleDbDataAdapter(Comm)
Ds.Clear()
OleA.Fill(Ds, "tblStud")
DataGridView1.DataSource = Ds
DataGridView1.DataMember = "tblStud"
Conn.Close()
End Sub
Private Sub PopulateDataGridE()
MyConnectS()
SQLStr = "SELECT * FROM tblEmployee ORDER BY ID"
Comm = New OleDbCommand(SQLStr, Conn)
OleA = New OleDbDataAdapter(Comm)
Ds.Clear()
OleA.Fill(Ds, "tblEmployee")
DataGridView1.DataSource = Ds
DataGridView1.DataMember = "tblEmployee"
Conn.Close()
End Sub
Private Sub btnStud_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStud.Click
Dim StrStud As Integer
StrStud = MsgBox("Do you want to see all the Student Records?", MsgBoxStyle.YesNoCancel)
If StrStud = vbYes Then
PopulateDataGridS()
btnStudF.Enabled = True
Else
StrStud = MsgBox("Do you want to change the Student Records", MsgBoxStyle.YesNoCancel)
If StrStud = vbYes Then
Form1.Show()
End If
End If
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnStudF.Enabled = False
btnEmpF.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim StrEmp As Integer
Try
StrEmp = MsgBox("Do you want to see all the Employee Records?", MsgBoxStyle.YesNoCancel)
If StrEmp = vbYes Then
PopulateDataGridE()
btnEmpF.Enabled = True
Else
StrEmp = MsgBox("Do you want to change the Employee Records", MsgBoxStyle.YesNoCancel)
If StrEmp = vbYes Then
Form3.Show()
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub btnStudF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStudF.Click
Form1.Show()
End Sub
Private Sub btnEmpF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmpF.Click
Form3.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub AxShockwaveFlash1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxShockwaveFlash1.Enter
End Sub
End Class
Imports System.Data.OleDb
Public Class Form3
Dim Conn As OleDbConnection
Dim Comm As OleDbCommand
Dim OleA As OleDbDataAdapter
Dim Ds As New DataSet
Dim SQLStr As String
Dim Drow As DataRow
Dim bool As Integer
Dim ID As Integer
Private Sub MyConnect()
Try
Conn = New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Application.StartupPath & "/Student.mdb")
Conn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK)
End Try
End Sub
Private Sub PopulateDataGrid()
MyConnect()
SQLStr = "SELECT * FROM tblEmployee ORDER BY ID"
Comm = New OleDbCommand(SQLStr, Conn)
OleA = New OleDbDataAdapter(Comm)
Ds.Clear()
OleA.Fill(Ds, "tblEmployee")
DataGridView1.DataSource = Ds
DataGridView1.DataMember = "tblEmployee"
Conn.Close()
End Sub
Private Sub DisableTxtBox()
txtEmp.Enabled = False
txtCont.Enabled = False
txtAdd.Enabled = False
End Sub
Private Sub EnableTxtBox()
txtEmp.Enabled = True
txtAdd.Enabled = True
txtCont.Enabled = True
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
EnableTxtBox()
btnAdd.Enabled = False
btnDel.Enabled = False
btnEdit.Enabled = False
btnSave.Enabled = True
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
MyConnect()
SQLStr = "INSERT INTO tblEmployee (EmpName, Address, Cont) VALUES ('" & txtEmp.Text & "', '" & txtAdd.Text & "', '" & txtCont.Text & "' )"
Comm = New OleDbCommand(SQLStr, Conn)
Comm.ExecuteNonQuery()
MessageBox.Show("Ok na ang bagong record.")
PopulateDataGrid()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
txtEmp.Clear()
txtCont.Clear()
txtAdd.Clear()
btnAdd.Enabled = True
btnSave.Enabled = False
btnDel.Enabled = True
btnQuit.Enabled = True
DisableTxtBox()
btnEdit.Enabled = True
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
Try
If btnEdit.Text = "." Then
If (SearchMe()) Then
EnableTxtBox()
btnEdit.Text = ","
btnSave.Enabled = True
btnAdd.Enabled = True
End If
Else
'UpDate ******************************************
MyConnect()
SQLStr = "UPDATE tblEmployee SET Address='" & txtAdd.Text & "',EmpName='" & txtEmp.Text & "', Cont='" & txtCont.Text & "' WHERE ID=" & ID & ""
Comm = New OleDbCommand(SQLStr, Conn)
Comm.ExecuteNonQuery()
MessageBox.Show("Record Updated!.....")
PopulateDataGrid()
DisableTxtBox()
btnEdit.Text = "."
btnSave.Enabled = False
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function SearchMe() As Boolean
Dim StrSearch As String = InputBox("Enter Employee Name", "Record Search", "")
If (StrSearch.Length > 0) Then
bool = 1
Else
bool = 0
End If
MyConnect()
SQLStr = "SELECT * FROM tblEmployee WHERE EmpName ='" & StrSearch & "'"
Comm = New OleDbCommand(SQLStr, Conn)
OleA = New OleDbDataAdapter(Comm)
Ds.Clear()
OleA.Fill(Ds, "tblEmployee")
If Ds.Tables("tblEmployee").Rows.Count > 0 Then
Drow = Ds.Tables("tblEmployee").Rows(0)
ID = Drow("ID")
txtAdd.Text = Drow("Address")
txtCont.Text = Drow("Cont")
txtEmp.Text = Drow("EmpName")
PopulateDataGrid()
SearchMe = True
Else
MessageBox.Show("Sorry! Name didn't match. Enter the correct name.")
SearchMe = False
PopulateDataGrid()
End If
End Function
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DisableTxtBox()
btnSave.Enabled = False
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
If (SearchMe()) Then
Try
If (MessageBox.Show("Delete all the " & txtEmp.Text & " Records? ", "Deleting of Record", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes) Then
MyConnect()
SQLStr = "DELETE FROM tblEmployee WHERE EmpName='" & txtEmp.Text & "'"
Comm = New OleDbCommand(SQLStr, Conn)
Comm.ExecuteNonQuery()
MessageBox.Show("Record Deleted!.....")
PopulateDataGrid()
Else
Exit Sub
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
If bool = 1 Then
MessageBox.Show("Record Does Not Exist!.....")
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PopulateDataGrid()
End Sub
End Class
Imports System.Data.OleDb
Public Class LoginForm1
Dim Comm As OleDbCommand
Dim Conn As OleDbConnection
Dim OleA As OleDbDataAdapter
Dim Ds As New DataSet
Dim SQLStr As String
Dim FrmStud As New Form2
Private Sub MyConnect()
Try
Conn = New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Application.StartupPath & "/Student.mdb")
Conn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK)
End Try
End Sub
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
MyConnect()
SQLStr = "SELECT COUNT(*) FROM tblSecurity WHERE UName='" & txtUName.Text & "' AND PWord='" & txtPWord.Text & "'"
Comm = New OleDbCommand(SQLStr, Conn)
Dim Result As Integer
Result = Comm.ExecuteScalar
If Result > 0 Then
FrmStud.ShowDialog()
Me.Close()
Else
MessageBox.Show("Invalid User Name or Password", "User Autentication")
End If
Conn.Close()
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyConnect()
End Sub
Private Sub txtPWord_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPWord.TextChanged
End Sub
End Class