VB .NET

VB .NET

Slip23

Q.1) Write a VB.NET program to create a table student (RollNo ,SName, Class). Insert the records (Max: 5). Update class of students to ‘TYBCA’ whose class is ‘SYBCA’ and display updated records in GridView. (Use MS Access to create db)  [Marks 20] 

Solution

Imports System.IO

Imports System.Data

Imports System.Data.OleDb

Public Class Slip23

    Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\BCA PAPER\TYBCA\VB.NET Practical\dbstudent1.mdb")

    Dim cmd As OleDbCommand

    Dim da As OleDbDataAdapter

    Dim dr As OleDbDataReader

    Dim dt As DataTable

    Dim r1 As DataRow

    Dim a As Integer

    Dim str As String

    Public Sub clear()

        TextBox1.Text = ""

        TextBox2.Text = ""

        TextBox3.Text = ""

    End Sub


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

            con.Open()

            str = "insert into dbstudent values(" & TextBox1.Text & ",' " & TextBox2.Text & " ',' " & TextBox3.Text & " ')"

            cmd = New OleDbCommand(str, con)

            cmd.ExecuteNonQuery()

            MsgBox("Record Save Successfully...")

            clear()

            con.Close()

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        a = InputBox("enter roll no")

        con.Open()

        str = "delete * from dbstudent where rollno=" & a & ""

        cmd = New OleDbCommand(str, con)

        cmd.ExecuteNonQuery()

        MsgBox("Record Delete Successfully...")

        clear()

        con.Close()

    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        con.Open()

        str = "update dbstudent set sname=' " & TextBox2.Text & " ',class=' " & TextBox3.Text & " ' where rollno= " & TextBox1.Text & " "

        cmd = New OleDbCommand(str, con)

        cmd.ExecuteReader()

        MsgBox("Update successfully")

        clear()

        con.Close()

    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        con.Open()

        Dim rno As Integer

        rno = InputBox("Enter the number")

        str = "select * from dbstudent where rollno=" & rno & " "

        cmd = New OleDbCommand(str, con)

        da = New OleDbDataAdapter(cmd)

        dt = New DataTable

        da.Fill(dt)

        If dt.Rows.Count = 0 Then

            MsgBox("Student id is not find")

            con.Close()

            Exit Sub

        End If

        r1 = dt.Rows(0)

        TextBox1.Text = r1.Item(0)

        TextBox2.Text = r1.Item(1)

        TextBox3.Text = r1.Item(2)

        con.Close()

    End Sub


End Class

BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post