VB .Net





Project VB.NET

1.     Develop  Tic Tac Toe Game Application using button control


                           



CODE:

Public Class Form1

    Dim a, count, ans As Integer

    Private Sub Btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click, Btn2.Click, Btn3.Click, Btn4.Click, Btn5.Click, Btn6.Click, Btn7.Click, Btn8.Click, Btn9.Click
        If (a = 0) Then
            sender.text = "0"
            a = 1
        Else
            sender.text = "X"
            a = 0
        End If
        sender.enabled = False
        cheek()
    End Sub

    Private Sub Btn1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn1.MouseEnter, Btn2.MouseEnter, Btn3.MouseEnter, Btn4.MouseEnter, Btn5.MouseEnter, Btn6.MouseEnter, Btn7.MouseEnter, Btn8.MouseEnter, Btn9.MouseEnter
       
 sender.backcolor = Color.Beige

    End Sub

    Private Sub Btn1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn1.MouseLeave, Btn2.MouseLeave, Btn3.MouseLeave, Btn4.MouseLeave, Btn5.MouseLeave, Btn6.MouseLeave, Btn7.MouseLeave, Btn8.MouseLeave, Btn9.MouseLeave
        sender.backcolor = Color.White
    End Sub
    Sub cheek()
 If (Btn1.Text = "0" And Btn2.Text = "0" And Btn3.Text = "0") Or (Btn4.Text = "0" And Btn5.Text = "0" And Btn6.Text = "0") Or (Btn7.Text = "0" And Btn8.Text = "0" And Btn9.Text = "0") Or (Btn1.Text = "0" And Btn4.Text = "0" And Btn7.Text = "0") Or (Btn2.Text = "0" And Btn5.Text = "0" And Btn8.Text = "0") Or (Btn3.Text = "0" And Btn6.Text = "0" And Btn9.Text = "0") Or (Btn1.Text = "0" And Btn5.Text = "0" And Btn9.Text = "0") Or (Btn3.Text = "0" And Btn5.Text = "0" And Btn7.Text = "0") Then
           
      MsgBox("Player one was Won", MsgBoxStyle.Information, "Result")
      start()

ElseIf (Btn1.Text = "X" And Btn2.Text = "X" And Btn3.Text = "X") Or (Btn4.Text = "X" And Btn5.Text = "X" And Btn6.Text = "X") Or (Btn7.Text = "X" And Btn8.Text = "X" And Btn9.Text = "X") Or (Btn1.Text = "X" And Btn4.Text = "X" And Btn7.Text = "X") Or (Btn2.Text = "X" And Btn5.Text = "X" And Btn8.Text = "X") Or (Btn3.Text = "X" And Btn6.Text = "X" And Btn9.Text = "X") Or (Btn1.Text = "X" And Btn5.Text = "X" And Btn9.Text = "X") Or (Btn3.Text = "X" And Btn5.Text = "X" And Btn7.Text = "X") Then
           
MsgBox("Player two was Won", MsgBoxStyle.Information, "Result")
      start()
       
Else
            count = count + 1
            tie()
      End If
    End Sub
    Sub tie()
        If (count = 9) Then
MsgBox("Excellent.....Game Was Tied.", MsgBoxStyle.Information , "Result")
            start()

        End If
    End Sub
    Sub start()
ans = MsgBox("Do You Want to Play Again.....",      MsgBoxStyle.YesNoCancel, "Play or Not")
        If (ans = 6) Then
            blank()
        Else
MsgBox("Thank you For Play.....See you Again.....", MsgBoxStyle.OkCancel, "Exit")
            Close()

        End If
    End Sub
   
Sub blank()
        Btn1.Enabled = True
        Btn1.Text = ""
        Btn2.Enabled = True
        Btn2.Text = ""
        Btn3.Enabled = True
        Btn3.Text = ""
        Btn4.Enabled = True
        Btn4.Text = ""
        Btn5.Enabled = True
        Btn5.Text = ""
        Btn6.Enabled = True
        Btn6.Text = ""
        Btn7.Enabled = True
        Btn7.Text = ""
        Btn8.Enabled = True
        Btn8.Text = ""
        Btn9.Enabled = True
        Btn9.Text = ""
        a = 0
        count = 0
    End Sub
End Class
















2.     Design Simple Calculator with appropriate function



                           



CODE:

Public Class calculator
    Dim no1 As Double
    Dim op As Char

    Private Sub b7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b7.Click, b10.Click, b00.Click, b0.Click, b1.Click, b2.Click, b3.Click, b4.Click, b5.Click, b6.Click, b8.Click, b9.Click
        TextBox1.Text &= sender.Text
    End Sub

    Private Sub div_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles div.Click, min.Click, mul.Click, plus.Click
        no1 = TextBox1.Text
        TextBox1.Clear()
        op = sender.text


    End Sub

    Private Sub clen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clen.Click
        TextBox1.Clear()
    End Sub

    Private Sub eql_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eql.Click
        If op = "+" Then
            TextBox1.Text = no1 + Val(TextBox1.Text)
        ElseIf op = "-" Then
            TextBox1.Text = no1 - TextBox1.Text
        ElseIf op = "x" Then
            TextBox1.Text = no1 * TextBox1.Text
        ElseIf op = "/" Then
            TextBox1.Text = no1 / TextBox1.Text
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim str As String
        Dim i As Integer
        str = TextBox1.Text
        For i = 0 To str.Length() - 1

        Next
        If str = "" Then
            MsgBox("value not available")
        Else
            TextBox1.Text = str.Remove(i - 1)
        End If

    End Sub
End Class















3.Take 2 Combobox set their roll no like cmbRollNo which contain number of students, second one cmbname which contains name of students. When we select RollNo then name of the student should display vice versa.


CODE:-

PublicClassForm1

PrivateSub ComboBox1_SelectedIndexChanged(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) HandlescmbRollNo.SelectedIndexChanged

cmbName.SelectedIndex = cmbRollNo.SelectedIndex

EndSub

PrivateSub ComboBox2_SelectedIndexChanged(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) HandlescmbName.SelectedIndexChanged

CmbRollNo.SelectedIndex = CmbName.SelectedIndex

EndSub
EndClass



4.Take the one listbox for foods menu items and display the selected menu items list in message box.


                                   


CODE:-

PublicClassForm1

PrivateSub Button1_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click

Dim I As Integer

Dim str As String = ""

For i = 0 To ListBox1.Items.Count – 1


If ListBox1.GetSelected(i) = TrueThen

str&= ListBox1.Items.Item(i) &vbNewLine

EndIf


Next

MsgBox(str, MsgBoxStyle.Information, "Ans")

EndSub

EndClass


5.Take the one checkedListBox for S.Y.B.C.A subject list and display the any three subjects from list in message box.



Public Class Form1

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

        Dim I As Integer

        Dim str As String
        For I = 0 To CheckedListBox1.Items.Count – 1


            If CheckedListBox1.GetSelected(I) = True Then

                str = CheckedListBox1.Items.Item(I) & vbNewLine

            End If

        Next
        For j = 0 To Str.length
            MsgBox(str, MsgBoxStyle.Information, "Ans")
            MessageBox.Show(str,&str,str)
        Next


    End Sub
End Class



6.Develop  Notepad  Application  with suitable menu option and dialog boxes.

                           



CODE:

Public Class Wordpade

    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click

        If Me.Text = "notepad" Then
            Dim ans As Integer
ans = MsgBox("do you want to save file?",    MsgBoxStyle.YesNo)
            If ans = 6 Then

                With SaveFileDialog1
                    .Filter = "text file|*.txt|rtf file|*.rtf"
                  If .ShowDialog() = Windows.Forms.DialogResult.OK Then
RichTextBox1.SaveFile(.FileName,   RichTextBoxStreamType.PlainText)
                        Me.Text = "notepad"
                    End If
                End With
                RichTextBox1.Clear()
            Else
                Me.Text = "notepad"
                RichTextBox1.Clear()
            End If

        Else
            Me.Text = "notepad"
            RichTextBox1.Clear()
        End If

    End Sub

    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        With OpenFileDialog1
            .Filter = "text file|*.txt|rtf file|*.rtf"
            If .ShowDialog() = Windows.Forms.DialogResult.OK Then
RichTextBox1.LoadFile(.FileName, RichTextBoxStreamType.PlainText)
                  Me.Text = .FileName
            End If
        End With
    End Sub

    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        If Me.Text = "notepad" Then
            With SaveFileDialog1
                .Filter = "text file|*.txt|rtf file|*.rtf"
                If .ShowDialog() = Windows.Forms.DialogResult.OK Then
RichTextBox1.SaveFile(.FileName,  RichTextBoxStreamType.PlainText)
                  Me.Text = .FileName

                End If
            End With
        Else
        RichTextBox1.SaveFile(Me.Text, RichTextBoxStreamType.PlainText)
        MsgBox("your file is save")
        End If
    End Sub




Private Sub SaveAsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveAsToolStripMenuItem.Click
        SaveFileDialog1.Filter = "text file|*.txt|Rtf file|*.rtf"
        SaveFileDialog1.Title = "Save as"
        If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            RichTxt.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
            Me.Text = SaveFileDialog1.FileName
        End If
    End Sub

    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub UndoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UndoToolStripMenuItem.Click
        RichTxt.Undo()
    End Sub

    Private Sub RedoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RedoToolStripMenuItem.Click
        RichTxt.Redo()
    End Sub

    Private Sub CutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CutToolStripMenuItem.Click
        RichTxt.Cut()
    End Sub

    Private Sub CopyToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CopyToolStripMenuItem.Click
        RichTxt.Copy()
    End Sub

    Private Sub PasteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PasteToolStripMenuItem.Click
        RichTxt.Paste()
    End Sub
  
    Private Sub AllSelectToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AllSelectToolStripMenuItem.Click
        RichTxt.SelectAll()
    End Sub

    Private Sub FontToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FontToolStripMenuItem.Click
        If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            RichTxt.SelectionFont = FontDialog1.Font
        End If
    End Sub

    Private Sub FontDialog1_Apply(sender As Object, e As EventArgs) Handles FontDialog1.Apply

    End Sub

    Private Sub ColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ColorToolStripMenuItem.Click
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            RichTxt.SelectionColor = ColorDialog1.Color
        End If
    End Sub

    Private Sub CenterToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CenterToolStripMenuItem.Click
        RichTxt.SelectionAlignment = HorizontalAlignment.Center
    End Sub

    Private Sub LeftToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LeftToolStripMenuItem.Click
        RichTxt.SelectionAlignment = HorizontalAlignment.Left

    End Sub

    Private Sub RightToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RightToolStripMenuItem.Click
        RichTxt.SelectionAlignment = HorizontalAlignment.Right
    End Sub

    Private Sub BulletToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BulletToolStripMenuItem.Click
        RichTxt.BulletIndent = 2
        RichTxt.SelectionBullet = True
    End Sub

    Private Sub ClearBulletToolStripMenuItem_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub ZoomToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ZoomToolStripMenuItem.Click

    End Sub

    Private Sub ToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem2.Click
        RichTxt.ZoomFactor = 2

    End Sub

    Private Sub ToolStripMenuItem3_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem3.Click
        RichTxt.ZoomFactor = 5

    End Sub

    Private Sub ToolStripMenuItem4_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem4.Click
        RichTxt.ZoomFactor = 10

    End Sub

    Private Sub ToolStripMenuItem5_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem5.Click
        RichTxt.ZoomFactor = 20
    End Sub

    Private Sub AboutMeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutMeToolStripMenuItem.Click
        Form2.Show()
    End Sub
    Private Sub Wordpad_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

End Clas


7.Develop Student Management desktop Application with registration and login from and display data from database

(1). Main page.


CODE:

Public Class Form1

Private Sub InsertToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertToolStripMenuItem.Click

        Form2.Show()
    End Sub

Private Sub DeleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteToolStripMenuItem.Click
        Form3.Show()
    End Sub

Private Sub UpdateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateToolStripMenuItem.Click
        Form4.Show()
    End Sub

Private Sub SelectToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectToolStripMenuItem.Click
        Form6.Show()
    End Sub

Private Sub FindToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindToolStripMenuItem.Click
        Form7.Show()
    End Sub
End Class


(2). Insert.


                           



CODE:

Imports System.Data.OleDb

Public Class Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       

   Try
            Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\BCA\prectical\pvb\student management\student1.mdb")
            Dim str As String
            Dim temp As Boolean

            If rdofemale.Checked = True Then
                temp = True
            Else
                temp = False
            End If
            str = "insert into stud values(" & txtrno.Text & ",'" & txtname.Text & "','" & txtadd.Text & "','" & cmbstream.Text & "','" & cmbdiv.Text & "'," & temp & ",'" & txtno.Text & "','" & txtcity.Text & "')"
            Dim cmd As New OleDbCommand(str, cnn)
            cnn.Open()
            cmd.ExecuteNonQuery()
            MsgBox("inserted")
            cnn.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        txtadd.Clear()
        txtcity.Clear()
        txtname.Clear()
        txtno.Clear()
        txtrno.Clear()
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class



(3). Update.


                           






CODE:

Imports System.Data.OleDb
Public Class Form4

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\BCA\prectical\pvb\student management\student1.mdb")
            Dim str As String

            str = "update stud set name='" & txtname.Text & "',stream='" & cmbstream.Text & "',division='" & cmbdiv.Text & "',mo= '" & txtno.Text & "',city='" & txtcity.Text & "' where roll_no=" & Form5.TextBox1.Text & ""
            Dim cmd As New OleDbCommand(str, cnn)
            cnn.Open()
            cmd.ExecuteNonQuery()
            MsgBox("update record")
            cnn.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        txtname.Clear()
        txtcity.Clear()
        txtno.Clear()
    End Sub
End Class


(4). Delete.






CODE:

Imports System.Data.OleDb
Public Class Form3

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
Dim cnn As New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\BCA\prectical\pvb\student management\student1.mdb")
          Dim str As String

          str = "delete from stud where roll_no = " & txtrno.Text & " "
          Dim cmd As New OleDbCommand(str, cnn)
          cnn.Open()
          cmd.ExecuteNonQuery()
          MsgBox("deleted record")
          cnn.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

(5). Select.  

CODE:

Imports System.Data.OleDb
Public Class Form6

    Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\BCA\prectical\pvb\student management\student1.mdb")
            Dim str As String

            str = "select * from stud"
            Dim cmd As New OleDbCommand(str, cnn)
            Dim da As New OleDbDataAdapter(cmd)
            Dim ds As New Data.DataSet
            da.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)
            cnn.Open()
            cnn.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

(6). Find.
                           



CODE:

Imports System.Data.OleDb
Public Class Form7

    Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\BCA\prectical\pvb\student management\student1.mdb")
            Dim str As String
str = "select roll_no,name,address,stream,gender,mo,city,   division from  stud "
            Dim cmd As New OleDbCommand(str, cnn)
            Dim dr As OleDbDataReader
            cnn.Open()
            dr = cmd.ExecuteReader
            While dr.Read
                cmbno.Items.Add(dr.Item(0))
                cmbname.Items.Add(dr.Item(1))
                cmbaddress.Items.Add(dr.Item(2))
                cmbstream.Items.Add(dr.Item(3))
                cmbgender.Items.Add(dr.Item(4))
                cmbmo.Items.Add(dr.Item(5))
                cmbcity.Items.Add(dr.Item(6))
                cmbdiv.Items.Add(dr.Item(7))

            End While
            cnn.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub cmbno_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbno.SelectedIndexChanged
        cmbname.SelectedIndex = cmbno.SelectedIndex
        cmbaddress.SelectedIndex = cmbno.SelectedIndex
        cmbstream.SelectedIndex = cmbno.SelectedIndex
        cmbdiv.SelectedIndex = cmbno.SelectedIndex
        cmbgender.SelectedIndex = cmbno.SelectedIndex
        cmbmo.SelectedIndex = cmbno.SelectedIndex
        cmbcity.SelectedIndex = cmbno.SelectedIndex


    End Sub

    Private Sub cmbname_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbname.SelectedIndexChanged
        cmbno.SelectedIndex = cmbname.SelectedIndex
        cmbaddress.SelectedIndex = cmbname.SelectedIndex
        cmbstream.SelectedIndex = cmbname.SelectedIndex
        cmbgender.SelectedIndex = cmbname.SelectedIndex
        cmbmo.SelectedIndex = cmbname.SelectedIndex
        cmbcity.SelectedIndex = cmbname.SelectedIndex
        cmbdiv.SelectedIndex = cmbname.SelectedIndex

    End Sub
    Private Sub cmbaddress_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbaddress.SelectedIndexChanged
        cmbno.SelectedIndex = cmbaddress.SelectedIndex
        cmbname.SelectedIndex = cmbaddress.SelectedIndex
        cmbstream.SelectedIndex = cmbaddress.SelectedIndex
        cmbgender.SelectedIndex = cmbaddress.SelectedIndex
        cmbmo.SelectedIndex = cmbaddress.SelectedIndex
        cmbcity.SelectedIndex = cmbaddress.SelectedIndex
        cmbdiv.SelectedIndex = cmbaddress.SelectedIndex
    End Sub
End Class




















8.Develop Library Management desktop Application with registration and login from and display data from database.




(1). Master page.




CODE:

Imports System.Data.OleDb
Public Class Library_Management_Report

    Private Sub InsertToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertToolStripMenuItem.Click
        Form1.Show()
    End Sub

    Private Sub UpdateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateToolStripMenuItem.Click
        update1.Show()
    End Sub

    Private Sub DeleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteToolStripMenuItem.Click
        delete.Show()
    End Sub

    Private Sub DisplayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayToolStripMenuItem.Click
        Try
            Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\bca\library.mdb")
            Dim cmd As New OleDbCommand("select * from library", cnn)
            Dim ad As New OleDbDataAdapter(cmd)
            Dim ds As New Data.DataSet
            ad.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub SerchToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SerchToolStripMenuItem.Click
        Search.Show()
    End Sub
End Class
                           















(2). Insert.   

CODE:



Imports System.Data.OleDb
Public Class Form1



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
Dim cnn As New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\bca\library.mdb")
            Dim str As String
str = "insert into library values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "'," & TextBox5.Text & ",'" & TextBox6.Text & "','" & TextBox7.Text & "')"
            Dim cmd As New OleDbCommand(str, cnn)
            cnn.Open()
            cmd.ExecuteNonQuery()
            cnn.Close()
            MsgBox("Record insert", MsgBoxStyle.Information, "Insert")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

(3). Update.




CODE:

Imports System.Data.OleDb
Public Class update1
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim cnn As New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\bca\library.mdb")
            Dim str As String
            str = "update library set BookName='" & TextBox2.Text & "',AuthorName='" & TextBox3.Text & "',Publisher='" & TextBox4.Text & "',Price=" & TextBox5.Text & ",IssueDate='" & TextBox6.Text & "',ReceiveDate='" & TextBox7.Text & "' where BookNo=" & TextBox1.Text & ""
            Dim cmd As New OleDbCommand(str, cnn)
            cnn.Open()
            cmd.ExecuteNonQuery()
            cnn.Close()
            MsgBox("Record update", MsgBoxStyle.Information, "Update")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

(4). Delete.

CODE:

Imports System.Data.OleDb
Public Class delete
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim cnn As New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\bca\library.mdb")
            Dim str As String
          str ="delete * from library where BookNo="&TextBox1.Text & ""
            Dim cmd As New OleDbCommand(str, cnn)
            cnn.Open()
            cmd.ExecuteNonQuery()
            cnn.Close()
            MsgBox("Record delete", MsgBoxStyle.Critical, "Delete")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class


(5). Search.

CODE:

Imports System.Data.OleDb
Public Class Search
    Private Sub Search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\bca\library.mdb")
            Dim str As String
            str = "select BookNo,BookName from library order by BookNo"
            Dim cmd As New OleDbCommand(str, cnn)
            Dim dr As OleDbDataReader
            cnn.Open()
            dr = cmd.ExecuteReader()
            While dr.Read
                ComboBox1.Items.Add(dr.Item(0))
                ComboBox2.Items.Add(dr.Item(1))
            End While
            cnn.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        ComboBox2.SelectedIndex = ComboBox1.SelectedIndex
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        ComboBox1.SelectedIndex = ComboBox2.SelectedIndex
    End Sub

End Class

Share this

Related Posts

Comment Here