VB .NET

VB .NET

Slip30

Q.1) Write a VB.NET program to create player table (Pid,PName,Game, no_of_matches). Insert records and update number of matches of ‘Sachin Tendulkar’ and display result in Crystal Report.(Use SQL to create db)  [Marks 20] 

Solution

Imports System.Data.SqlClient
Public Class frmSlip30
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim n As Integer
Dim str As String

Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
txtGame.Clear()
txtNOM.Clear()
txtPid.Clear()
txtPid.Focus()
End Sub

Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
cn = New SqlConnection("Data Source=BHUSHAN\SQLEXPRESS;Initial Catalog=player;Integrated Security=True;Pooling=False")
cn.Open()
str = "insert into player values(" & CInt(txtPid.Text) & ",'" & txtPname.Text & "','" & txtGame.Text & "'," & CInt(txtNOM.Text) & ")"
cmd = New SqlCommand(str, cn)
n = cmd.ExecuteNonQuery
If (n > 0) Then
MsgBox("Record Inserted Successfully")
End If
cn.Close()
End Sub

Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
cn = New SqlConnection("Data Source=BHUSHAN\SQLEXPRESS;Initial Catalog=player;Integrated Security=True;Pooling=False")
cn.Open()
Dim a As Integer
a = InputBox("Enter No. of Matches you want to update:")
str = "update player set no_of_matches=" & CInt(a) & " �where PName='Sachin Tendulkar' "
cmd = New SqlCommand(str, cn)
n = cmd.ExecuteNonQuery
If (n > 0) Then
MsgBox("Record Updated Successfully")
form2.show()
End If
cn.Close()
End Sub

Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click
Form2.Show()
End Sub
End Class

BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

1 Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete
Previous Post Next Post