LIBRARY MANAGEMENT SYSTEM
Student Details:
Book Details
Coding:
Imports System.Data.Sqlclient
Public Class Form2
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ComboBox1.Visible = False
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
TextBox5.Text = " "
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
con.Open()
cmd = New SqlCommand("insert into book values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')", con)
cmd.ExecuteNonQuery()
con.Close()
Label8.Visible = True
Label8.Text = "Record Inserted"
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Visible = True
con = New SqlConnection("Data source=COMPUTER10;Initial Catalog=library;Integrated Security=TRUE")
Label8.Visible = False
Try
Dim cmd1 As New SqlCommand
Dim ad1 As New SqlDataAdapter
Dim d1 As New DataSet
cmd1 = New SqlCommand("select bname from book", con)
ad1 = New SqlDataAdapter(cmd1)
d1 = New DataSet
ad1.Fill(d1)
Dim i As Integer
For i = 0 To d1.Tables(0).Rows.Count - 1
ComboBox1.Items.Add(d1.Tables(0).Rows(i).Item(0))
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
con.Open()
cmd = New SqlCommand("delete from book where bname='" & ComboBox1.SelectedItem & "'", con)
cmd.ExecuteNonQuery()
con.Close()
Label8.Visible = True
Label8.Text = "Record Deleted"
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Try
con.Open()
Dim cmd2 As New SqlCommand
Dim ad2 As New SqlDataAdapter
Dim ds As New DataSet
cmd2 = New SqlCommand("select * from book where bname='" & ComboBox1.SelectedItem & "'", con)
ad2 = New SqlDataAdapter(cmd2)
ad2.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
TextBox1.Text = ds.Tables(0).Rows(0).Item(0)
TextBox2.Text = ds.Tables(0).Rows(0).Item(1)
TextBox3.Text = ds.Tables(0).Rows(0).Item(2)
TextBox4.Text = ds.Tables(0).Rows(0).Item(3)
TextBox5.Text = ds.Tables(0).Rows(0).Item(4)
End If
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Imports System.Data.SqlClient
Public Class Form1
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ComboBox1.Visible = False
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
TextBox5.Text = " "
TextBox6.Text = " "
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
con.Open()
cmd = New SqlCommand("insert into student values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')", con)
cmd.ExecuteNonQuery()
con.Close()
Label9.Visible = True
Label9.Text = "Record Inserted"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Visible = True
con = New SqlConnection("Data source=COMPUTER10;Initial Catalog=library;Integrated Security=TRUE")
Label9.Visible = False
Try
Dim cmd1 As New SqlCommand
Dim ad1 As New SqlDataAdapter
Dim d1 As New DataSet
cmd1 = New SqlCommand("select sid from student", con)
ad1 = New SqlDataAdapter(cmd1)
d1 = New DataSet
ad1.Fill(d1)
Dim i As Integer
For i = 0 To d1.Tables(0).Rows.Count - 1
ComboBox1.Items.Add(d1.Tables(0).Rows(i).Item(0))
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
con.Open()
cmd = New SqlCommand("delete from student where sid='" & ComboBox1.SelectedItem & "'", con)
cmd.ExecuteNonQuery()
con.Close()
Label9.Visible = True
Label9.Text = "Record Deleted"
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Form2.Show()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Try
con.Open()
Dim cmd2 As New SqlCommand
Dim ad2 As New SqlDataAdapter
Dim ds As New DataSet
cmd2 = New SqlCommand("select * from student where sid='" & ComboBox1.SelectedItem & "'", con)
ad2 = New SqlDataAdapter(cmd2)
ad2.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
TextBox1.Text = ds.Tables(0).Rows(0).Item(0)
TextBox2.Text = ds.Tables(0).Rows(0).Item(1)
TextBox3.Text = ds.Tables(0).Rows(0).Item(2)
TextBox4.Text = ds.Tables(0).Rows(0).Item(3)
TextBox5.Text = ds.Tables(0).Rows(0).Item(4)
TextBox6.Text = ds.Tables(0).Rows(0).Item(5)
End If
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Database:
create database library
use library
create table student(sname varchar(20),sid varchar(20),dept varchar(20),cyear varchar(20),duration varchar(20),nob int)
select * from book
create table book(bname varchar(20),author varchar(20),noa numeric,noi numeric,tot numeric) |