Dim connection As New ADODB.Connection Dim LV As ListViewItem
Private Sub Connect()
On Error GoTo x connection.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\BestInstit.mdb") MsgBox("connected") Exit Sub x: MsgBox("Database Connecting Error, Contact Your System Administrator", MsgBoxStyle.Critical) Application.Exit() End Sub
Private Sub Clear()
TextBox1.Text = "" TextBox2.Text = "" TextBox1.Focus() End Sub
Private Sub LoadList()
ListView1.Items.Clear() Dim rs As New ADODB.Recordset rs.Open("Select * from StudentInfo order by ANo", connection, 2, 3) If Not rs.EOF Then Do While Not rs.EOF LV = New ListViewItem LV.Text = rs.Fields("ANo").Value LV.SubItems.Add(rs.Fields("SName").Value) ListView1.Items.Add(LV) rs.MoveNext() Application.DoEvents() Loop End If rs.Close() End Sub
Private Sub SaveRecord()
Dim rs As New ADODB.Recordset rs.Open("select * from StudentInfo where ANo like '" & TextBox1.Text & "'", connection, 2, 3) If Not rs.EOF Then rs.Fields("ANo").Value = TextBox1.Text rs.Fields("SName").Value = TextBox2.Text rs.Update() Application.DoEvents() Else rs.AddNew() rs.Fields("ANo").Value = TextBox1.Text rs.Fields("SName").Value = TextBox2.Text rs.Update() End If Application.DoEvents() rs.Close() Call Clear() End Sub
Private Sub DeleteRecord(ByVal code As String)
connection.Execute("Delete from StudentInfo where ANo like '" & code & "'") ' Call Clear() End Sub
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click If Not Trim(TextBox1.Text) = "" Then If Not Trim(TextBox2.Text) = "" Then Call SaveRecord() Call LoadList() End If End If End Sub
Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click Dim choice As Integer If Not Trim(TextBox1.Text) = "" Then choice = MsgBox("Are you sure, want to Delete this Record", MsgBoxStyle.YesNo) If choice = 6 Then Call DeleteRecord(TextBox1.Text) Call Clear() Call LoadList() End If End If End Sub
Private Sub Button3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button3.Click Call Clear() End Sub
Private Sub Button4_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button4.Click Me.Close() End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load Call Connect() Call Clear() Call LoadList() End Sub
Private Sub ListView1_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ListView1.Click Dim iv As New ListViewItem If ListView1.SelectedItems.Count > 0 Then iv = Me.ListView1.SelectedItems.Item(0) Me.TextBox1.Text = iv.SubItems(0).Text Me.TextBox2.Text = iv.SubItems(1).Text End If End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
End Sub End Class SERVER Imports System.Data.SqlClient Imports SmartComponents
Public Class Form1
Dim iv As New ListViewItem
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click If Not Trim(Me.SmartText1.Text) = "" Then Call SaveData() Call Clear() Call LoadList() Else MsgBox("Invalid Code") Me.SmartText1.Focus() End If End Sub
Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click Dim choice As Integer If Not Trim(Me.SmartText1.Text) = "" Then choice = MsgBox("Are you sure to delete this record", MsgBoxStyle.YesNo) If (choice = 6) Then Call DeleteRecord(Me.SmartText1.Text) Call Clear() Call LoadList() End If Else MsgBox("Invalid Code", MsgBoxStyle.Information) Me.SmartText1.Focus() End If End Sub
Private Sub Button3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button3.Click Call Clear() End Sub
Private Sub Button4_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button4.Click Me.Close() End Sub Private Sub DeleteRecord(ByVal data As String) If DBFunctions.Exists("Select * from Sample Where CCode LIKE '" & data & "'") = True Then DBFunctions.Execute_NonQuery("Delete from Sample where CCode = '" & data & "'") MsgBox("Data Deleted Successfully", MsgBoxStyle.Information) Else MsgBox("Data not found", MsgBoxStyle.Information) End If End Sub
Private Sub SaveData()
Dim Str As String Dim SQL As SQLFunctions Str = DBFunctions.GetConnectionString() SQL = New SQLFunctions SQL.ConnectionString = Str SQL.TableName = "Sample" SQL.Add("CCode", Me.SmartText1.Text) SQL.Add("CName", Me.SmartText2.Text) If DBFunctions.Exists("Select * from Sample where CCode like '" & Me.SmartText1.Text & "'") = True Then SQL.UpdateConditions = "where CCode like '" & Me.SmartText1.Text & "'" SQL.ExecuteUpdateQuery() Else SQL.ExecuteInsertQuery() End If Application.DoEvents() End Sub
Private Sub Clear()
Me.SmartText1.Text = "" Me.SmartText2.Text = "" Me.SmartText1.Focus() End Sub
Private Sub LoadList()
Dim Reader As SqlDataReader Reader = DBFunctions.GetDataReader("Select * from Sample") ListView1.Items.Clear() Do While Reader.Read iv = New ListViewItem iv.Text = Reader.Item("CCode").ToString iv.SubItems.Add(Reader.Item("CName").ToString) Me.ListView1.Items.Add(iv) Loop Reader.Close() End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load Call Clear() Call LoadList() End Sub
Private Sub ListView1_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ListView1.Click If ListView1.SelectedItems.Count > 0 Then iv = Me.ListView1.SelectedItems.Item(0) Me.SmartText1.Text = iv.SubItems(0).Text Me.SmartText2.Text = iv.SubItems(1).Text End If End Sub End Class