Practical 28: Student Data Manipulation:
Practical 28: Student Data Manipulation:
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
Dim conn As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\HP\Documents\VB.NET\Student_Records\Student_Records\StudentDatabase1.mdf;Integrated Security=True")
Dim sql As String = "SELECT * FROM Student"
Dim dap As New SqlDataAdapter(sql, conn)
Dim ds As New DataSet
Private Sub Button_insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_insert.Click
Try
conn.Open()
Dim cmd As New SqlCommand("Insert into Student (Studentno,Name,Address) Values ('" & TextBox_no.Text & "','" & TextBox_name.Text & "','" & TextBox_add.Text & "');", conn)
Dim i As Integer = cmd.ExecuteNonQuery()
If i > 0 Then
MsgBox("insert")
Else
MsgBox("not insert")
End If
dap.Fill(ds, "Student")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Student"
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'StudentDatabase1DataSet.Student' table. You can move, or remove it, as needed.
Me.StudentTableAdapter.Fill(Me.StudentDatabase1DataSet.Student)
'TODO: This line of code loads data into the 'StudentDatabase1DataSet.Student' table. You can move, or remove it, as needed.
Me.StudentTableAdapter.Fill(Me.StudentDatabase1DataSet.Student)
End Sub
Private Sub Button_update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_update.Click
Try
conn.Open()
Dim cmd As New SqlCommand("Update Student Set Name ='" & TextBox_name.Text & "' ,Address ='" & TextBox_add.Text & "' Where Studentno ='" & TextBox_no.Text & "';")
cmd.Connection = conn
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
MsgBox("your value update")
Else
MsgBox("not update")
End If
conn.Close()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub Button_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_delete.Click
Try
conn.Open()
Dim cmd As New SqlCommand("Delete from Student Where Studentno ='" & TextBox_no.Text & "';")
cmd.Connection = conn
Dim i As Integer = cmd.ExecuteNonQuery()
If i > 0 Then
MsgBox("value delete")
Else
MsgBox("value not delete")
End If
conn.Close()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
End Class
Comments
Post a Comment