VB .NET
Slip27
Q.1) Write a VB.NET program to accept the details of product (pid, pname, expiry_date, price).
Store it into the database and display it on the Crystal Report.(Use SQL Server) [Marks 20]
Solution
Public Class frmSlip27
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim datadapter As New SqlDataAdapter
Dim dt As New DataTable
Dim cnt As New Integer
Dim str As String
Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
txtP_Id.Clear()
txtP_Name.Clear()
txtExp.Clear()
txtPrice.Clear()
txtP_Id.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=product2;Integrated Security=True;Pooling=False")
cn.Open()
str = "insert into product2 values (" & CInt(txtP_Id.Text) & " , '" & txtP_Name.Text & "', '" & txtExp.Text & "', " & CInt(txtPrice.Text) & ")"
cmd = New SqlCommand(str, cn)
cnt = cmd.ExecuteNonQuery
If (cnt > 0) Then
MsgBox("Record Inserted Successfully")
End If
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
Tags:
VB .NET