Imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form
Dim RsSAve As New ADODB.Recordset
Dim RsSearch As New ADODB.Recordset
Dim RS, RS1 As New ADODB.Recordset
Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Connection()
RsSearch = New ADODB.Recordset
RsSearch.Open("select * from usertable ", CON, 1, 2, )
RsSearch.MoveFirst()
Call ShowRecord()
txtgender.Text = ("Choose to GENDER")
txtgender.Items.Add("MALE")
txtgender.Items.Add("FEMALE")
End Sub
Public Sub ShowRecord()
txtserial.Text = RsSearch.Fields("Serial").Value
txtname.Text = RsSearch.Fields("name").Value
txtgender.Text = RsSearch.Fields("gender").Value
txtaddress.Text = RsSearch.Fields("address").Value
txtcity.Text = RsSearch.Fields("city").Value
txtstate.Text = RsSearch.Fields("state").Value
txtphone1.Text = RsSearch.Fields("phone1").Value
End Sub
Public Sub clear()
txtserial.Text = ""
txtname.Text = ""
txtgender.Text = ""
txtaddress.Text = ""
txtcity.Text = ""
txtstate.Text = ""
txtphone1.Text = ""
If RsSearch.State = 1 Then RsSearch.Close()
RsSearch.Open("select * from usertable ", Con, 1, 2)
RsSearch.MoveLast()
txtserial.Text = RsSearch.Fields("Serial").Value
txtserial.Text = Val(txtserial.Text) + 1
End Sub
Public Sub SaveRecord()
RsSAve.Fields("Serial").Value = txtserial.Text
RsSAve.Fields("name").Value = txtname.Text
RsSAve.Fields("gender").Value = txtgender.Text
RsSAve.Fields("address").Value = txtaddress.Text
RsSAve.Fields("city").Value = txtcity.Text
RsSAve.Fields("state").Value = txtstate.Text
RsSAve.Fields("phone1").Value = txtphone1.Text
End Sub
Private Sub AddNewRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewRecordToolStripMenuItem.Click
Call clear()
End Sub
Private Sub LoadRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadRecordToolStripMenuItem.Click
Call Connection()
RsSearch = New ADODB.Recordset
RsSearch.Open("select * from usertable ", CON, 1, 2, )
RsSearch.MoveFirst()
Call ShowRecord()
End Sub
Private Sub SaveRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveRecordToolStripMenuItem.Click
RsSAve = New ADODB.Recordset
Dim msg
msg = MsgBox("Are you sure to save this record.....?", MsgBoxStyle.Question + MsgBoxStyle.YesNo)
If msg = vbYes Then
RsSAve.Open("Select * from usertable", CON, 1, 2)
RsSAve.AddNew()
Call SaveRecord()
RsSAve.Update()
End If
End Sub
Private Sub UpdatingRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdatingRecordToolStripMenuItem.Click
RsSAve = New ADODB.Recordset
RsSAve.Open("select * from usertable where Serial=" & Trim(txtserial.Text) & "", CON, 1, 2)
Call SaveRecord()
RsSAve.Update()
MsgBox("Record update successfully......")
End Sub
Private Sub DeleteRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteRecordToolStripMenuItem.Click
On Error Resume Next
Dim Ans
Ans = MsgBox("Are you sure to delete this record....?", vbYesNo + vbQuestion)
If Ans = vbYes Then
CON.Execute("delete from UserTable where Serial=" & Trim(txtserial.Text) & "")
RsSearch.MovePrevious()
Call clear()
Call ShowRecord()
End If
End Sub
Private Sub first_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles first.Click
On Error Resume Next
RsSearch.MoveFirst()
Call ShowRecord()
End Sub
Private Sub prev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles prev.Click
On Error Resume Next
RsSearch.MovePrevious()
Call ShowRecord()
End Sub
Private Sub Nex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nex.Click
On Error Resume Next
RsSearch.MoveNext()
Call ShowRecord()
End Sub
Private Sub last_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles last.Click
On Error Resume Next
RsSearch.MoveLast()
Call ShowRecord()
End Sub
Public Function OnlyCharacter(ByVal key As String) As Boolean
If ((key >= 65 And key <= 90) Or (key >= 97 And key <= 122) Or key = 8) Then
OnlyCharacter = False
Else
MsgBox("only enter the value of character")
OnlyCharacter = True
End If
End Function
Public Function OnlyNumeric(ByVal Key As String) As Boolean
If (Key >= 48 And Key <= 57) Or Key = 8 Then
OnlyNumeric = False
Else
MsgBox("only enter the value of Number")
OnlyNumeric = True
End If
End Function
Private Sub txtphone1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtphone1.KeyPress
e.Handled = OnlyNumeric(Asc(e.KeyChar))
End Sub
Private Sub txtname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtname.KeyPress
e.Handled = OnlyCharacter(Asc(e.KeyChar))
End Sub
Private Sub txtcity_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcity.KeyPress
e.Handled = OnlyCharacter(Asc(e.KeyChar))
End Sub
Private Sub txtstate_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtstate.KeyPress
e.Handled = OnlyCharacter(Asc(e.KeyChar))
End Sub
Private Sub search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles search.Click
If txtsearch.Text = "" Then MsgBox("Please type Item Name", MsgBoxStyle.Critical, "Enter Text") : Exit Sub
Dim MYDA As OleDbDataAdapter = New OleDbDataAdapter
Dim MYDS As DataSet = New DataSet
RS = New ADODB.Recordset
RS.Open("SELECT * FROM usertable WHERE name LIKE '" & txtsearch.Text & "%' ", CON, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
MYDA.Fill(MYDS, RS, "ITEM")
DataGrid1.DataSource = MYDS.Tables(0)
End Sub
Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
Call clear()
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub DataGrid1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGrid1.CellContentClick
End Sub
End Class
Mentor Edit:
Attached image(s)
This post has been edited by AdamSpeight2008: 13 August 2009 - 06:21 AM

New Topic/Question
Reply




MultiQuote








|