0% found this document useful (0 votes)
23 views4 pages

Database Program

The document is a Visual Basic .NET code for a Windows Forms application that manages student records in a SQL database. It includes functionalities to insert, display, update, and delete student records using a DataGridView and various buttons for user interaction. The application handles exceptions and provides feedback to the user through message boxes.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Database Program

The document is a Visual Basic .NET code for a Windows Forms application that manages student records in a SQL database. It includes functionalities to insert, display, update, and delete student records using a DataGridView and various buttons for user interaction. The application handles exceptions and provides feedback to the user through message boxes.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Imports System.

Data

Imports [Link]

Public Class Form1

Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\win10\Documents\Visual


Studio 2010\Projects\datainsert\datainsert\[Link];Integrated Security=True;User Instance=True")

Dim cmd As SqlCommand

Dim ds As DataSet

Private Sub Display_Records()

Try

Dim cmd As New SqlCommand("select * from Student", con)

Dim da As New SqlDataAdapter(cmd)

ds = New DataSet

[Link](ds, "Student")

[Link] = [Link]("Student")

Catch ex As Exception

[Link]([Link])

End Try

End Sub
Private Sub ClearControls()

[Link] = ""

[Link] = ""

[Link] = ""

End Sub

Private Sub Button1_Click(ByVal sender As [Link], ByVal e As [Link]) Handles [Link]

Try

cmd = New SqlCommand("insert into Student values('" & CInt([Link]) & "','" & [Link] & "','" &
[Link] & "')", con)

[Link]()

[Link]()

[Link]()

MsgBox("record is inserted")

Catch ex As Exception

[Link]([Link])

End Try

End Sub

Private Sub Button2_Click(ByVal sender As [Link], ByVal e As [Link]) Handles [Link]

Display_Records()

End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

Dim index As Integer = [Link]

Dim selectedRow As DataGridViewRow = [Link](index)

[Link] = [Link](0).[Link]

[Link] = [Link](1).[Link]

[Link] = [Link](2).[Link]

End Sub
Private Sub Button3_Click(ByVal sender As [Link], ByVal e As [Link]) Handles [Link]

Try

Dim cmd As New SqlCommand("delete from Student where rno=@rn", con)

[Link]("@rn", [Link]).Value = CInt([Link])

[Link]()

Dim flg As Integer = [Link]

If flg > 0 Then

[Link]("Record Deleted Successfully")

ClearControls()

Display_Records()

End If

Catch ex As Exception

[Link]([Link])

Finally

[Link]()

End Try

End Sub

Private Sub Button4_Click(ByVal sender As [Link], ByVal e As [Link]) Handles [Link]

Try

Dim cmd As New SqlCommand("update student set name='" & [Link] & "',course='" & [Link] & "'
where rno=" & [Link] & "", con)

[Link]()

[Link]()

[Link]()

MsgBox("Record is updated")
Catch ex As Exception

MsgBox([Link])

End Try

Display_Records()

ClearControls()

End Sub

Private Sub Button6_Click(ByVal sender As [Link], ByVal e As [Link]) Handles [Link]

Try

Dim cmd As New SqlCommand("select * from student where rno='" & [Link] & "'", con)

Dim dt As New DataTable

Dim da As New SqlDataAdapter(cmd)

[Link](dt)

[Link] = dt

Catch ex As Exception

MsgBox([Link])

End Try

End Sub

End Class

You might also like