Practical No 27
Practical No 27
27
Understand the concept of select and insert data in database table.
I. Practical Significance:
In VB.Net for connection & communication with database to data retrieval & updating
with data access controls.
Experiments and practice: Plan to perform experiments and practices to use the
results to solve the computer group related problems.
• Write an NET program for database connection with retrieve and store.
• Compile/Debug/Save the „VB.NET‟
V. Practical Outcome
Write a VB.Net Code to store and retrieve data in Database Table.
• Follow safety
• Follow ethical
INSERT
UPDATE
DELETE
• ExecuteScaler()
Executes the query, and returns the first column of the first row in the result set
returned by the query. Extra columns or rows are ignored. dr =
cmd.ExecuteScaler();
– ExecuteReader()
Display all columns and all rows at client-side environment. In other words, we can
say that they display datatables client-side.
dr = cmd.ExecuteReader();
– ExecuteNonQuery()
Something is done by the database but nothing is returned by the database. dr =
cmd.ExecuteNonQuery();
IX. Precautions
• https://www.tutorialspoint.com/vb.net/vb.net
1. Write a program to insert the data & retrieve the data from database.
Imports System.Data.OleDb
Dim da As OleDbDataAdapter
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
con.Open()
da.Fill(ds, “student”)
DataGrid1.DataSource = ds
DataGrid1.DataMember = “student”
con.Close()
End Sub
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
Close()
End Sub
End Class
• ExecuteScaler():
dr = cmd.ExecuteScaler();
• ExecuteReader():
dr = cmd.ExecuteReader();
• ExecuteNonQuery():
dr = cmd.ExecuteNonQuery();
Dim strQuery As String = “select Name, ContentType, Data from tblFiles where
id=@id”
Dim cmd As SqlCommand = New SqlCommand(strQuery)
cmd.Parameters.Add(“@id”, SqlDbType.Int).Value = 1
download(dt)
End If
• Design a simple Windowsform for accepting the details of Using the connected
architecture of ADO.NET, perform the following operations:
• Insert
• Search
• Update
• Delete
• Insert Record
• Search Record
• Update Record
• Delete Record
Imports System.Data.OleDb
Dim da As OleDbDataAdapter
con.Open()
If txtNo.Text = “” Then
Else
cmd.ExecuteNonQuery()
txtNo.Clear()
txtName.Clear()
txtAdd.Clear()
txtDOJ.Clear()
con.Close()
End If
End Sub
con.Open()
If txtNo.Text = “” Then
Else
cmd.ExecuteNonQuery()
MsgBox(” Record Successfully Deleted”)
txtNo.Clear()
txtNo.Focus()
con.Close()
End If
End Sub
con.Open()
cmd.ExecuteNonQuery()
txtNo.Clear()
txtName.Clear()
txtAdd.Clear()
txtDOJ.Clear()
con.Close()
Else
MsgBox(” Please Enter Employment Number”)
End If
End Sub
con.Open()
da.Fill(ds, “Employee”)
DataGrid1.DataSource = ds
DataGrid1.DataMember = “Employee”
con.Close()
End Sub
If txtNo.Text = “” Then
Else
da.Fill(ds, “Employee”)
DataGrid1.DataSource = ds.Tables(“Employee”)
da.Dispose()
con.Close()
txtNo.Clear()
txtNo.Focus()
End If
End Sub
End Class
OUTPUT: