Prg_26TO30_DATABASE
Prg_26TO30_DATABASE
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim a As Integer = 0
Private Sub BtnLogin_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As SqlConnection = New SqlConnection("Data
Source=(LocalDB)\v11.0;AttachDbFilename=E:\2024\VB.NET\DATABASE_PRG\p26\p26\Database1.
mdf;Integrated Security=True")
Dim cmd As SqlCommand = New SqlCommand("select * from login where username='"
+ Txtunm.Text + "' and password='" + TxtPass.Text + "'", con)
Dim sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
If (dt.Rows.Count > 0) Then
MsgBox("Login SuccessFully...")
Else
MsgBox("Invalid Username or Password")
a = a + 1
If a >= 3 Then
Me.Close()
End If
End If
End Sub
O/P:
27) Create a Employee table with the fields mentioned on the form in SQL. Add few
record in this table using SQL. Design following form in vb.net and perform
navigations.
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim con As New SqlConnection("Data
Source=(LocalDB)\v11.0;AttachDbFilename=D:\2024\VB.NET\DATABASE_PRG\p27\p27\Database1.
mdf;Integrated Security=True")
Dim cmd As New SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim tb1 As New DataTable()
Dim bm As BindingManagerBase
Dim str As String
End Sub
O/P:
a. Create the form that shows the basic operations on Student database (in SQL) like insert, delete
and update.
b. The navigation operation on database.
Imports System.Data
Imports System.Data.SqlClient
cmd.ExecuteNonQuery()
MsgBox("Record is Inserted Sucessfully")
TxtNo.Clear()
TxtName.Clear()
TxtAddress.Clear()
End Sub
cmd.Parameters.AddWithValue("@Empno", TxtNo.Text)
cmd.ExecuteNonQuery()
MsgBox("Record is Deleted")
TxtNo.Clear()
End Sub
End Class
O/P:
29) Design the form as shown below
Create table in SQL with following fields. Perform all functions indicated on buttons.
Imports System.Data
Imports System.Data.SqlClient
End Sub
End Sub
cmd.Parameters.AddWithValue("@Empno", TxtEno.Text)
cmd.Parameters.AddWithValue("@Empnm", TxtName.Text)
cmd.Parameters.AddWithValue("@Job", TxtJob.Text)
cmd.Parameters.AddWithValue("@Salary", TxtSal.Text)
cmd.Parameters.AddWithValue("@DeptNo", TxtDeptNo.Text)
cmd.Parameters.AddWithValue("@Date", DateTimePicker1.Text)
cmd.Parameters.AddWithValue("@ManagerNo", TxtMaNo.Text)
cmd.Parameters.AddWithValue("@Comm", TxtComm.Text)
cmd.ExecuteNonQuery()
MsgBox("Record is Updated Sucessfully")
TxtEno.Clear()
TxtComm.Clear()
TxtDeptNo.Clear()
DateTimePicker1.Text = Today
TxtJob.Clear()
TxtMaNo.Clear()
TxtName.Clear()
TxtSal.Clear()
End Sub
cmd.ExecuteNonQuery()
MsgBox("Record is Inserted Sucessfully")
TxtEno.Clear()
TxtComm.Clear()
TxtDeptNo.Clear()
DateTimePicker1.Text = Today
TxtJob.Clear()
TxtMaNo.Clear()
TxtName.Clear()
TxtSal.Clear()
End Sub
cmd.Parameters.AddWithValue("@Empno", TxtEno.Text)
cmd.ExecuteNonQuery()
MsgBox("Record is Deleted")
TxtEno.Clear()
TxtComm.Clear()
TxtDeptNo.Clear()
DateTimePicker1.Text = Today
TxtJob.Clear()
TxtMaNo.Clear()
TxtName.Clear()
TxtSal.Clear()
End Sub
Public Sub employee()
str = "Select * from Employee"
cmd = New SqlCommand(str, con)
da = New SqlDataAdapter(cmd)
ds = New DataSet
da.Fill(ds, "Employee")
TxtEno.Text = ds.Tables("Employee").Rows(a).Item(0)
TxtName.Text = ds.Tables("Employee").Rows(a).Item(1)
TxtJob.Text = ds.Tables("Employee").Rows(a).Item(2)
TxtSal.Text = ds.Tables("Employee").Rows(a).Item(3)
TxtDeptNo.Text = ds.Tables("Employee").Rows(a).Item(4)
DateTimePicker1.Text = ds.Tables("Employee").Rows(a).Item(5)
TxtMaNo.Text = ds.Tables("Employee").Rows(a).Item(6)
TxtComm.Text = ds.Tables("Employee").Rows(a).Item(7)
End Sub
If dr.Read Then
TxtEno.Text = dr.Item(0)
TxtName.Text = dr.Item(1)
TxtJob.Text = dr.Item(2)
TxtSal.Text = dr.Item(3)
TxtDeptNo.Text = dr.Item(4)
DateTimePicker1.Text = dr.Item(5)
TxtMaNo.Text = dr.Item(6)
TxtComm.Text = dr.Item(7)
Else
MsgBox("No is not exit")
End If
Call employee()
End Sub
O/P:
30) Design the form as shown below:
Create table in SQL with following fields. Perform all functions indicated on
buttons and populate data in DataGridView.
Imports System.Data
Imports System.Data.SqlClient