2019 Pattern
Slip: 1
A) Write a VB.Net Program to display the numbers continuously in TextBox by
clicking on Button.
Answer :
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
TextBox1.Text = Second(DateTime.Now)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Enabled = True
Timer1.Interval = 1000
Timer1.Start()
End Sub
End Class
:
B) Write a VB.Net program to accept the details of Employee (ENO, EName Salary)
and store it into the database and display it on gridview control.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Desktop\New folder\Emp.accdb")
Dim adpt As New OleDbDataAdapter("Select * from Emp", con)
Dim ds As New DataSet
Dim cmd As New OleDbCommand
Public Function display()
adpt.Fill(ds, "Emp")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Emp"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into Emp values(" & TextBox1.Text & ",'" & TextBox2.Text & "'," & TextBox3.Text & ")"
con.Open()
cmd.ExecuteNonQuery()
con.Close()
ds.Clear()
display()
End Sub
End Class
Answer:
Imports System.Data.SqlClient
Public Class Form1
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
txtE_Id.Clear()
txtE_Name.Clear()
txtDes.Clear()
txtDOJ.Clear()
txtE_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=Employee2;Integrated Security=True;Pooling=False")
cn.Open()
str = "insert into employee2 values (" & CInt(txtE_Id.Text) & " , '" & txtE_Name.Text & "', '" & txtDes.Text & "', '" & txtDOJ.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
DataGridView1.DataSource = Nothing
cn = New SqlConnection("Data Source=Bhushan\SQLEXPRESS;Initial Catalog=Employee2;Integrated Security=True;Pooling=False")
cn.Open()
str = "select * from employee2"
cmd = New sqlcommand(str, cn)
datadapter = New sqlDataAdapter(cmd)
datadapter.Fill(dt)
DataGridView1.DataSource = dt
cn.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Slip: 2
A) Write a Vb.Net program to move the Text “Pune University” continuously from Left
to Right and Vice Versa.
Answer :
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Label1.Left >= Me.Width Then
Label1.Left = -100
Else
Label1.Left = Label1.Left + 10
End If
End Sub
End Class
:
B)Write a C#.Net program to create a base class Department and derived classes Sales and
Human Resource. Accept the details of both departments and display them in proper
format.
namespace ConsoleApp4
{
class Department
{
public string name;
public void display()
{
Console.WriteLine("Here is department");
}
}
// derived class of Sales
class Sales : Department
{
public void getName()
{
Console.WriteLine("Department name is " + name);
}
}
// derived class of Human Resource
class Human_Resource : Department
{
public void getName()
{
Console.WriteLine("Department name is " + name);
}
}
class Program
{
static void Main(string[] args)
{
// object of derived class
Sales dept = new Sales();
// access field and method of base class
dept.name = "Sales";
dept.display();
// access method from own class
dept.getName();
// object of derived class
Human_Resource dept1 = new Human_Resource();
// access field and method of base class
dept1.name = "HR";
dept1.display();
// access method from own class
dept1.getName();
Console.ReadLine();
}
}
}
Slip 3
A) Write a program in C# .Net to create a function for the sum of two numbers.
Answer :
namespace WinFormsApp18
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int Sum(int a, int b)
{
return a + b;
}
private void button1_Click(object sender, EventArgs e){
int a = Convert .ToInt32 (textBox1.Text);
int b = Convert .ToInt32 (textBox2.Text);
int c = Sum (a, b);
label5.Text = c.ToString();
}
}
}
:
B) Write a VB.NET program to create teacher table (Tid, TName, subject) Insert the
records (Max: 5). Search record of a teacher whose name is “Seeta” and display result.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\teacher.accdb")
Dim adpt As New OleDbDataAdapter("Select * from teacher", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "teacher")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "teacher"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into teacher values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "')"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
Private Sub TextBox4_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox4.KeyDown
ds.Clear()
Dim adp As New OleDbDataAdapter("select * from teacher Where Name like '%" & TextBox4.Text & "%'", con)
adp.Fill(ds, "search")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "search"
End Sub
End Class
Slip 4
A) Design a VB.net form to pick a date from DateTimePicker Control and display day,
month and year in separate text boxes.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = "Year : " & DateTimePicker1.Value.Year
Label2.Text = "Month : " & DateTimePicker1.Value.Month
Label3.Text = "Day : " & DateTimePicker1.Value.Day
End Sub
End Class
:
B) Create a web application to insert 3 records inside the SQL database table having
following fields ( DeptId, DeptName, EmpName, Salary). Update the salary for any one
employee and increment it to 15% of the present salary. Perform delete operation on
one row of the database table.
Slip 5
A) Write a VB.NET program to accept a character from keyboard and check whether it
is vowel or consonant. Also display the case of that character.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As Char
Dim str As String
a = TextBox1.Text
If (TextBox1.Text.Length <= 1) Then
If Char.IsUpper(a) Then
str = "Upper Case"
Else
str = "Lower Case"
End If
If (a = "a" Or a = "e" Or a = "i" Or a = "o" Or a = "u" Or
a = "A" Or a = "E" Or a = "I" Or a = "O" Or a = "U") Then
MessageBox.Show(TextBox1.Text & " is " & str & " Vowel")
Else
MessageBox.Show(TextBox1.Text & " is " & str & " Consonant")
End If
End If
End Sub
Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
Dim a As String
a = TextBox1.Text
If (TextBox1.Text.Length > 1) Then
Label2.Text = "Only One Characters Allowed...!"
Else
Label2.Text = ""
End If
End Sub
End Class
:
B) Design a web application form in ASP.Net having loan amount, interest rate and
duration fields. Calculate the simple interest and perform necessary validation i.e.
Ensures data has been entered for each field. Checking for non-numeric value. Assume
suitable web-form controls and perform necessary validation.
Slip 6
A) Write ASP.Net program that displays the names of some flowers in two columns.
Bind a label to the RadioButtonList so that when the user selects an option from the list
and clicks on a button, the label displays the flower selected by the user.
Answer :
:
B) Write a VB.NET program to create movie table (Mv_Name, Release_year,
Director). Insert the records (Max: 5). Delete the records of movies whose release year
is 2022 and display appropriate message in message box.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\movie.accdb")
Dim adpt As New OleDbDataAdapter("Select * from movie", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "movie")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "movie"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into movie values('" & TextBox1.Text & "'," & TextBox2.Text & ",'" & TextBox3.Text & "')"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "DELETE FROM movie WHERE Release_year = " & TextBox2.Text
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Deleted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
End Class
Slip 7
A) Write a ASP.Net program to accept a number from the user in a textbox control and
throw an exception if the number is not a perfect number. Assume suitable controls on
the web form.
Answer :
:
B) Write a VB.NET program to create a table student (Roll No, SName, Class,City).
Insert the records (Max: 5). Update city of students to ‘Pune’ whose city is ‘Mumbai’
and display updated records in GridView.
Answer :
Slip 8
A) List of employees is available in listbox. Write ASP.Net application to add
selected or all records from listbox to Textbox (assume multi-line property of textbox is
true).
Answer :
:
B) Write a c#.Net program for multiplication of matrices.
Slip 9 A) Write a Menu driven program in C#.Net to perform following functionality:
Addition, Multiplication, Subtraction, Division.
Answer :
namespace WinFormsApp18
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void addtionToolStripMenuItem_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = a+b;
label3.Text = "+";
label5.Text = c.ToString();
}
private void substractionToolStripMenuItem_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = a - b;
label3.Text = "-";
label5.Text = c.ToString();
}
private void divisonToolStripMenuItem_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = a / b;
label3.Text = "/";
label5.Text = c.ToString();
}
private void multiplicationToolStripMenuItem_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = a * b;
label3.Text = "*";
label5.Text = c.ToString();
}
}
}
:
B) Create an application in ASP.Net that allows the user to enter a number in the
textbox named "getnum". Check whether the number in the textbox "getnum" is
palindrome or not. Print the message accordingly in the label control named lbldisplay
when the user clicks on the button "check".
Slip 10
A) Write a program that demonstrates the use of primitive data types in C#. The
program should also support the type conversion of :
● Integer to String
● String to Integer
Answer :
namespace WinFormsApp19
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int num = Convert.ToInt32(textBox1.Text);
label1.Text = "Before conversion : " + num.GetType();
String str = Convert.ToString(num);
label2.Text = "After conversion: " + str.GetType();
}
private void button2_Click(object sender, EventArgs e)
{
label1.Text = "Before conversion : " + textBox1.Text.GetType();
int num = Convert.ToInt32(textBox1.Text);
label2.Text = "After conversion: " + num.GetType();
}
}
}
:
B) Write ASP.Net program to connect to the master database in SQL Server in the
Page_Load event. When the connection is established, the message “Connection has
been established” should be displayed in a label in the form .
Slip 11
A) Write a ASP.Net program that gets user input such as the user name, mode of
payment, appropriate credit card. After the user enters the appropriate values the
Validation button validates the values entered.
Answer :
:
B) Write C# program to make a class named Fruit with a data member to calculate the
number of fruits in a basket. Create two other class named Apples and Mangoes to
calculate the number of apples and mangoes in the basket. Display total number of
fruits in the basket.
Answer :
Slip 12
A) Write ASP.Net program that displays a button in green color and it should change
into yellow when the mouse moves over it.
Answer :
:
B) Write a VB.NET program to create player table (PID, PName, Game,
no_of_matches). Insert records and update number of matches of ‘Rohit Sharma’ and
display result in data grid view.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\player.accdb")
Dim adpt As New OleDbDataAdapter("Select * from player", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "player")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "player"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into player values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "'," & TextBox4.Text & ")"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "UPDATE player SET no_of_matches = " & TextBox4.Text & " WHERE PName = '" & TextBox2.Text & "'"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Updated Successfully...!")
End If
con.Close()
con.Close()
ds.Clear()
display()
End Sub
End Class
Slip 13
A) Write a VB.net program for blinking an image.
Answer :
Public Class Form1
Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles Timer1.Tick
If PictureBox1.Visible Then
PictureBox1.Visible = False
Else
PictureBox1.Visible = True
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Interval = 1000
Timer1.Start()
End Sub
End Class
:
B) Write a C# Program to accept and display ‘n’ student’s details such as Roll. No,
Name, marks in three subjects, using class. Display percentage of each student.
Answer :
Slip 14
A) Write a program in C#.Net to find the sum of all elements of the array.
Answer :
namespace WinFormsApp27
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
int a,b=0,c;
for(int i = 0; i < listBox1.Items.Count; i++)
{
a = Convert.ToInt32(listBox1.Items[i]);
c = a + b;
b = c;
}
MessageBox.Show("Addtion is : " + b);
}
}
}
:
B) Write a C#.Net Program to define a class Person having members –name, address.
Create a subclass called employee with member staffed, salary. Create ‘n’ objects of the
Employee class and display all the details of the Employee.
Answer :
Slip 15
A) Write ASP.Net application to create a user control that contains a list of colors. Add
a button to the Web Form which when clicked changes the color of the form to the
color selected from the list.
Answer :
Public Class Form1
Private Sub RedToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RedToolStripMenuItem.Click
Me.BackColor = Color.Red
End Sub
Private Sub GreenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GreenToolStripMenuItem.Click
Me.BackColor = Color.Green
End Sub
Private Sub BlueToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BlueToolStripMenuItem.Click
Me.BackColor = Color.Blue
End Sub
End Class
:
B) Write a C#.Net Program to accept and display ‘n’ customer’s details such as
customer_no, Name, address ,itemno, quantity price . Display total price of all item.
Slip 16
A) Write ASP.Net program to create a user control that receives the user name and
password from the user and validates them. If the user name is "DYP" and the password
is "Pimpri", then the user is authorized, otherwise not.
Answer :
:
B) Define a class supplier with fields – sid, name, address, pincode. Write a C#.Net
Program to accept the details of ‘n’ suppliers and display it.
Answer :
Slip17
A) Write a C#.Net application to display the vowels from a given String.
Answer :
namespace WinFormsApp21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String str = (textBox1.Text);
char[] chars = str.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
switch (chars[i])
{
case 'A' or 'a':
listBox1.Items.Add(chars[i].ToString());
break;
case 'E' or 'e':
listBox1.Items.Add(chars[i].ToString());
break;
case 'I' or 'i':
listBox1.Items.Add(chars[i].ToString());
break;
case 'O' or 'o':
listBox1.Items.Add(chars[i].ToString());
break;
case 'U' or 'u':
listBox1.Items.Add(chars[i].ToString());
break;
}
}
}
}
}
:
B) 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 data grid view.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\product.accdb")
Dim adpt As New OleDbDataAdapter("Select * from product", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "product")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "product"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into product values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & DateTimePicker1.Value & "'," & TextBox4.Text & ")"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
End Class
Slip 18
A) Write a VB.NET program to accept a number from user through input box and
display its multiplication table into the list box.
Answer :
Public Class Form1
Dim a As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As Integer
a = TextBox1.Text
For b = 1 To 10
ListBox1.Items.Add(a * b)
Next
Console.ReadLine()
End Sub
End Class
:
B) Write ASP.Net program containing the following controls:
• ListBox
• Button
• Image
• Label
The listbox is used to list items available in a store. When the user clicks on an
item in the listbox, its image is displayed in the image control. When the user clicks the
button, the cost of the selected item is displayed in the control.
Answer :
Slip 19
A) Write a VB.NET program to check whether enter string is palindrome or not.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str, rev As String
str = TextBox1.Text
rev = StrReverse(str)
If (str = rev) Then
MessageBox.Show("String is Palindrome : " & str)
Else
MessageBox.Show("String is Not Palindrome : " & str)
End If
End Sub
End Class
:
B) "How is the book ASP.NET with C# by Wrox publication?"
Give the user three choices :
i)Good ii)Satisfactory iii)Bad.
Provide a VOTE button. After user votes, present the result in percentage using labels
next to the choices.
Answer :
Slip 20
A) Write a VB.NET program to generate Sample Tree View control.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TreeView1.Nodes.Add("Master")
TreeView1.Nodes(0).Nodes.Add("Student Details")
TreeView1.Nodes(0).Nodes.Add("Teacher Details")
TreeView1.Nodes.Add("Examination")
TreeView1.Nodes(1).Nodes.Add("Internal Exam")
TreeView1.Nodes(1).Nodes.Add("External Exam")
TreeView1.Nodes(1).Nodes.Add("Practical Exam")
End Sub
End Class
:
B) Write a Web application in ASP.Net that generates the “IndexOutOfRange”
exception when a button is clicked. Instead of displaying the above exception, it
redirects the user to a custom error page. All the above should be done with the trace
for the page being enabled.
Answer :
Slip 21
A) Write a VB.NET program to accept sentences in text box and count the number of
words and display the count in message box.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String
str = TextBox1.Text
Dim I, Count As Integer
Dim arr() As Char = str.ToCharArray
For I = 0 To arr.Length - 1
If arr(I) = " " Then
Count = Count + 1
End If
Next
MsgBox(Count + 1 & " words")
End Sub
End Class
:
B) Write ASP.Net application for the following:
1. Create a table EMP(eno, ename, edesignation, salary, joindate)
2. Insert a Record.
3. Update a record
Answer :
Slip 22
A) Write a program in C# to create a function to swap the values of two integers.
Answer :
:
B) Write a Vb.net program to design the following form; it contains the three menus
Color (Red, Blue, and Green), Window (Maximize, Minimize, and Restore) and Exit.
On Selection of any menu or submenu result should affect the form control( for
example if user selected Red color from Color menu back color of form should get
changed to Red and if user selected Maximize from Window Menu then form should
get maximized).
Answer :
Public Class Form1
Private Sub RedToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RedToolStripMenuItem.Click
Me.BackColor = Color.Red
End Sub
Private Sub GreenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GreenToolStripMenuItem.Click
Me.BackColor = Color.Green
End Sub
Private Sub BlueToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BlueToolStripMenuItem.Click
Me.BackColor = Color.Blue
End Sub
Private Sub MaximizeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MaximizeToolStripMenuItem.Click
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub MiniMToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MiniMToolStripMenuItem.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub RestoreToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RestoreToolStripMenuItem.Click
Me.WindowState = FormWindowState.Normal
End Sub
End Class
Slip 23
A) Write a program in C# to create a function to display the n terms of Fibonacci
sequence.
Answer :
namespace WinFormsApp22
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a, b=0, c=1, d;
a = Convert.ToInt32(textBox1.Text);
listBox1.Items.Add(b);
listBox1.Items.Add(c);
for (int i = 0; i < a; i++)
{
d = b + c;
listBox1.Items.Add(d);
b = c;
c = d;
}
}
}
}
:
B) Create the application in ASP.Net that accepts name, password ,age , email id, and
user id. All the information entry is compulsory. Password should be reconfirmed. Age
should be within 21 to 30. Email id should be valid. User id should have at least a
capital letter and digit as well as length should be between 7 and 20 characters.
Answer :
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="validationinasp._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<main>
<table style="width: 66%;">
<tr>
<td class="style1" colspan="3" align="center">
<asp:Label ID="lblmsg"
Text="Registration Form"
runat="server" />
</td>
</tr>
<tr>
<td class="style3">
Candidate:
</td>
<td class="style2">
<asp:DropDownList ID="ddlcandidate" runat="server" style="width:239px">
<asp:ListItem>Please Choose a Candidate</asp:ListItem>
<asp:ListItem>M H Kabir</asp:ListItem>
<asp:ListItem>Steve Taylor</asp:ListItem>
<asp:ListItem>John Abraham</asp:ListItem>
<asp:ListItem>Venus Williams</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvcandidate"
runat="server" ControlToValidate ="ddlcandidate"
ErrorMessage="Please choose a candidate"
InitialValue="Please choose a candidate">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
House:
</td>
<td class="style2">
<asp:RadioButtonList ID="rblhouse" runat="server" RepeatLayout="Flow">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Yellow</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvhouse" runat="server"
ControlToValidate="rblhouse" ErrorMessage="Enter your house name" >
</asp:RequiredFieldValidator>
<br />
</td>
</tr>
<tr>
<td class="style3">
Class:
</td>
<td class="style2">
<asp:TextBox ID="txtclass" runat="server"></asp:TextBox>
</td>
<td>
<asp:RangeValidator ID="rvclass"
runat="server" ControlToValidate="txtclass"
ErrorMessage="Enter your class (6 - 12)" MaximumValue="12"
MinimumValue="6" Type="Integer">
</asp:RangeValidator>
</td>
</tr>
<tr>
<td class="style3">
Email:
</td>
<td class="style2">
<asp:TextBox ID="txtemail" runat="server" style="width:250px">
</asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator ID="remail" runat="server"
ControlToValidate="txtemail" ErrorMessage="Enter your email"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style3" style="height: 21px">
Password:</td>
<td class="style2" style="height: 21px">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox></td>
<td style="height: 21px">
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator"
ControlToCompare="TextBox2" ControlToValidate="TextBox3">*password must match with confirm password</asp:CompareValidator></td>
</tr>
<tr>
<td class="style3" style="height: 21px">
Confirm Password:</td>
<td class="style2">
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox></td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3" style="height: 21px">
Name:</td>
<td class="style2">
<asp:TextBox ID="TextBox4" runat="server" ></asp:TextBox> </td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Name is required"
ControlToValidate="TextBox4">*Name is required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmail"
ValidationExpression="^[a-zA-Z]*$" ControlToValidate="TextBox4"
runat="server">enter only alphabets</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style3" style="height: 21px">
Enter Number</td>
<td class="style2">
<asp:TextBox ID="TextBox8" runat="server" ></asp:TextBox> </td> </td>
<td>
</td>
</tr>
<tr>
<td class="style3" style="height: 21px">
</td>
<td class="style2">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style3" align="center" colspan="3">
</td>
</tr>
</table>
</main>
</asp:Content>
Slip 24
A) Write a program in C#.Net to create a function to check whether a number is prime or
not.
Answer :
namespace WinFormsApp26
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static String prime(int a)
{
Boolean isprime = true;
int b = a/2;
for(int i = 2; i <= b; i++)
{
if(a % 2 == 0)
{
isprime = false;
break;
}
}
if (isprime)
{
return a + " is Prime Number";
}
else
{
return a + " is Not Prime Number";
}
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(prime(Convert.ToInt32(textBox1.Text)));
}
}
}
:
B) Write a VB.NET program to create Author table (aid, aname, book_ name). Insert the
records (Max 5). Delete a record of author who has written “VB.NET book” and
display remaining records on the data grid view. (Use MS Access to create db.)
Answer :
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\Author.accdb")
Dim adpt As New OleDbDataAdapter("Select * from Author", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "Author")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Author"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into Author values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "')"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "DELETE FROM Author WHERE book_name='" & TextBox3.Text & "'"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Deleted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
End Class
Slip 25
A) Write a program in C#.Net to create a function to calculate the sum of the individual
digits of a given number.
Answer :
:
B) Create a Web Application in ASP.Net to display all the Empname and Deptid of the
employee from the database using SQL source control and bind it to GridView.
Database fields are(DeptId, DeptName, EmpName, Salary).
Create Table Alter Table Drop Table Type Your DDL Query Here
Answer :
Slip 26
A). Write a program in C#.Net to create a recursive function to find the factorial of a
given number
Answer :
:
B) Write a ASP.Net program to create a Login Module which adds Username and
Password in the database. Username in the database should be a primary key.
Answer :
Slip 27
A) Write a program in C#.Net to find the length of a string.
Answer :
namespace WinFormsApp24
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a = textBox1.Text.Length;
MessageBox.Show("Length : " + a);
}
}
}
:
B) Create a web application in ASP.Net which may have a textbox. Now user must type
some data into it, the data he can enter is only 255 characters. After he crosses the limit
then the last word should not by typed and at the same time color of textbox
should be red.
Slip 28
A) Write a program in C#.Net to read n numbers in an array and display it in reverse
order.
Answer :
namespace WinFormsApp23
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
listBox2.Items.Clear();
for (int i = listBox1.Items.Count-1; i >= 0; i--)
{
listBox2.Items.Add (listBox1.Items[i]);
}
}
}
}
:
B) Write a VB.NET program to create a table Patient (PID, PName, Contact No,
Disease). Insert five records into table and display appropriate message in message box.
ENo EName Salary
Slip 29
A) Write a program in C#.Net to separate the individual characters from a String.
Answer :
using System;
class Program {
static void Main(string[] args) {
string inputString = "Hello, world!";
char[] characters = inputString.ToCharArray();
Console.WriteLine("Individual characters from the string: ");
foreach (char c in characters) {
Console.Write(c + " ");
}
Console.ReadLine();
}
}
:
B) Write a VB.NET program to accept the details of customer (CName, Contact No,
Email_id). Store it into the database with proper validation and display appropriate
message by using Message box.
Answer :
Imports System.Data.SqlClient
Public Class CustomerForm
' Database connection string
Dim connectionString As String = "Data Source=localhost\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=True"
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
' Get the customer details from textboxes
Dim cname As String = txtName.Text.Trim()
Dim contactNo As String = txtContactNo.Text.Trim()
Dim email As String = txtEmail.Text.Trim()
' Validate the inputs
If cname = "" Then
MessageBox.Show("Please enter customer name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
If contactNo = "" Or Not IsNumeric(contactNo) Then
MessageBox.Show("Please enter valid contact number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
If email = "" Or Not email.Contains("@") Then
MessageBox.Show("Please enter valid email address.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
' Insert the customer details into the database
Using connection As New SqlConnection(connectionString)
Dim query As String = "INSERT INTO Customers (CName, ContactNo, Email) VALUES (@CName, @ContactNo, @Email)"
Dim command As New SqlCommand(query, connection)
command.Parameters.AddWithValue("@CName", cname)
command.Parameters.AddWithValue("@ContactNo", contactNo)
command.Parameters.AddWithValue("@Email", email)
connection.Open()
Dim rowsAffected As Integer = command.ExecuteNonQuery()
connection.Close()
If rowsAffected > 0 Then
MessageBox.Show("Customer details saved successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Failed to save customer details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Using
End Sub
End Class
Slip 30
A) Write a VB.NET program to design following screen, accept the details from the user. Clicking on Submit button Net Salary should be calculated and displayed into the Textbox. Display the Messagebox informing the Name and Net Salary of employee.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label10.Text = (Int(TextBox2.Text) + Int(TextBox3.Text) + Int(TextBox4.Text) + Int(TextBox5.Text) + Int(TextBox6.Text) + Int(TextBox7.Text) + Int(TextBox8.Text))
Label12.Text = Int(TextBox6.Text) + Int(TextBox7.Text) + Int(TextBox8.Text)
Label14.Text = Label10.Text - Label12.Text
MessageBox.Show("Employee Name : " & TextBox1.Text & Environment.NewLine & "Total Salary is : " & Label14.Text)
End Sub
Private Sub TextBox2_Leave(sender As Object, e As EventArgs) Handles TextBox2.Leave
TextBox3.Text = (TextBox2.Text * 31) / 100
TextBox4.Text = (TextBox2.Text * 9) / 100
End Sub
End Class
:
B) Write a VB.NET program to accept the details Supplier (SupId, SupName, Phone
No, Address) store it into the database and display it.
Answer :
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\Supplier.accdb")
Dim adpt As New OleDbDataAdapter("Select * from Supplier", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "Supplier")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Supplier"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into Supplier values(" & TextBox1.Text & ",'" & TextBox2.Text & "'," & TextBox3.Text & ",'" & TextBox4.Text & "')"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
End Class
Slip: 1
A) Write a VB.Net Program to display the numbers continuously in TextBox by
clicking on Button.
Answer :
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
TextBox1.Text = Second(DateTime.Now)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Enabled = True
Timer1.Interval = 1000
Timer1.Start()
End Sub
End Class
:
B) Write a VB.Net program to accept the details of Employee (ENO, EName Salary)
and store it into the database and display it on gridview control.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Desktop\New folder\Emp.accdb")
Dim adpt As New OleDbDataAdapter("Select * from Emp", con)
Dim ds As New DataSet
Dim cmd As New OleDbCommand
Public Function display()
adpt.Fill(ds, "Emp")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Emp"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into Emp values(" & TextBox1.Text & ",'" & TextBox2.Text & "'," & TextBox3.Text & ")"
con.Open()
cmd.ExecuteNonQuery()
con.Close()
ds.Clear()
display()
End Sub
End Class
Answer:
Imports System.Data.SqlClient
Public Class Form1
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
txtE_Id.Clear()
txtE_Name.Clear()
txtDes.Clear()
txtDOJ.Clear()
txtE_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=Employee2;Integrated Security=True;Pooling=False")
cn.Open()
str = "insert into employee2 values (" & CInt(txtE_Id.Text) & " , '" & txtE_Name.Text & "', '" & txtDes.Text & "', '" & txtDOJ.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
DataGridView1.DataSource = Nothing
cn = New SqlConnection("Data Source=Bhushan\SQLEXPRESS;Initial Catalog=Employee2;Integrated Security=True;Pooling=False")
cn.Open()
str = "select * from employee2"
cmd = New sqlcommand(str, cn)
datadapter = New sqlDataAdapter(cmd)
datadapter.Fill(dt)
DataGridView1.DataSource = dt
cn.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Slip: 2
A) Write a Vb.Net program to move the Text “Pune University” continuously from Left
to Right and Vice Versa.
Answer :
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Label1.Left >= Me.Width Then
Label1.Left = -100
Else
Label1.Left = Label1.Left + 10
End If
End Sub
End Class
:
B)Write a C#.Net program to create a base class Department and derived classes Sales and
Human Resource. Accept the details of both departments and display them in proper
format.
namespace ConsoleApp4
{
class Department
{
public string name;
public void display()
{
Console.WriteLine("Here is department");
}
}
// derived class of Sales
class Sales : Department
{
public void getName()
{
Console.WriteLine("Department name is " + name);
}
}
// derived class of Human Resource
class Human_Resource : Department
{
public void getName()
{
Console.WriteLine("Department name is " + name);
}
}
class Program
{
static void Main(string[] args)
{
// object of derived class
Sales dept = new Sales();
// access field and method of base class
dept.name = "Sales";
dept.display();
// access method from own class
dept.getName();
// object of derived class
Human_Resource dept1 = new Human_Resource();
// access field and method of base class
dept1.name = "HR";
dept1.display();
// access method from own class
dept1.getName();
Console.ReadLine();
}
}
}
Slip 3
A) Write a program in C# .Net to create a function for the sum of two numbers.
Answer :
namespace WinFormsApp18
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int Sum(int a, int b)
{
return a + b;
}
private void button1_Click(object sender, EventArgs e){
int a = Convert .ToInt32 (textBox1.Text);
int b = Convert .ToInt32 (textBox2.Text);
int c = Sum (a, b);
label5.Text = c.ToString();
}
}
}
:
B) Write a VB.NET program to create teacher table (Tid, TName, subject) Insert the
records (Max: 5). Search record of a teacher whose name is “Seeta” and display result.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\teacher.accdb")
Dim adpt As New OleDbDataAdapter("Select * from teacher", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "teacher")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "teacher"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into teacher values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "')"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
Private Sub TextBox4_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox4.KeyDown
ds.Clear()
Dim adp As New OleDbDataAdapter("select * from teacher Where Name like '%" & TextBox4.Text & "%'", con)
adp.Fill(ds, "search")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "search"
End Sub
End Class
Slip 4
A) Design a VB.net form to pick a date from DateTimePicker Control and display day,
month and year in separate text boxes.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = "Year : " & DateTimePicker1.Value.Year
Label2.Text = "Month : " & DateTimePicker1.Value.Month
Label3.Text = "Day : " & DateTimePicker1.Value.Day
End Sub
End Class
:
B) Create a web application to insert 3 records inside the SQL database table having
following fields ( DeptId, DeptName, EmpName, Salary). Update the salary for any one
employee and increment it to 15% of the present salary. Perform delete operation on
one row of the database table.
Slip 5
A) Write a VB.NET program to accept a character from keyboard and check whether it
is vowel or consonant. Also display the case of that character.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As Char
Dim str As String
a = TextBox1.Text
If (TextBox1.Text.Length <= 1) Then
If Char.IsUpper(a) Then
str = "Upper Case"
Else
str = "Lower Case"
End If
If (a = "a" Or a = "e" Or a = "i" Or a = "o" Or a = "u" Or
a = "A" Or a = "E" Or a = "I" Or a = "O" Or a = "U") Then
MessageBox.Show(TextBox1.Text & " is " & str & " Vowel")
Else
MessageBox.Show(TextBox1.Text & " is " & str & " Consonant")
End If
End If
End Sub
Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
Dim a As String
a = TextBox1.Text
If (TextBox1.Text.Length > 1) Then
Label2.Text = "Only One Characters Allowed...!"
Else
Label2.Text = ""
End If
End Sub
End Class
:
B) Design a web application form in ASP.Net having loan amount, interest rate and
duration fields. Calculate the simple interest and perform necessary validation i.e.
Ensures data has been entered for each field. Checking for non-numeric value. Assume
suitable web-form controls and perform necessary validation.
Slip 6
A) Write ASP.Net program that displays the names of some flowers in two columns.
Bind a label to the RadioButtonList so that when the user selects an option from the list
and clicks on a button, the label displays the flower selected by the user.
Answer :
:
B) Write a VB.NET program to create movie table (Mv_Name, Release_year,
Director). Insert the records (Max: 5). Delete the records of movies whose release year
is 2022 and display appropriate message in message box.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\movie.accdb")
Dim adpt As New OleDbDataAdapter("Select * from movie", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "movie")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "movie"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into movie values('" & TextBox1.Text & "'," & TextBox2.Text & ",'" & TextBox3.Text & "')"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "DELETE FROM movie WHERE Release_year = " & TextBox2.Text
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Deleted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
End Class
Slip 7
A) Write a ASP.Net program to accept a number from the user in a textbox control and
throw an exception if the number is not a perfect number. Assume suitable controls on
the web form.
Answer :
:
B) Write a VB.NET program to create a table student (Roll No, SName, Class,City).
Insert the records (Max: 5). Update city of students to ‘Pune’ whose city is ‘Mumbai’
and display updated records in GridView.
Answer :
Slip 8
A) List of employees is available in listbox. Write ASP.Net application to add
selected or all records from listbox to Textbox (assume multi-line property of textbox is
true).
Answer :
:
B) Write a c#.Net program for multiplication of matrices.
Slip 9 A) Write a Menu driven program in C#.Net to perform following functionality:
Addition, Multiplication, Subtraction, Division.
Answer :
namespace WinFormsApp18
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void addtionToolStripMenuItem_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = a+b;
label3.Text = "+";
label5.Text = c.ToString();
}
private void substractionToolStripMenuItem_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = a - b;
label3.Text = "-";
label5.Text = c.ToString();
}
private void divisonToolStripMenuItem_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = a / b;
label3.Text = "/";
label5.Text = c.ToString();
}
private void multiplicationToolStripMenuItem_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = a * b;
label3.Text = "*";
label5.Text = c.ToString();
}
}
}
:
B) Create an application in ASP.Net that allows the user to enter a number in the
textbox named "getnum". Check whether the number in the textbox "getnum" is
palindrome or not. Print the message accordingly in the label control named lbldisplay
when the user clicks on the button "check".
Slip 10
A) Write a program that demonstrates the use of primitive data types in C#. The
program should also support the type conversion of :
● Integer to String
● String to Integer
Answer :
namespace WinFormsApp19
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int num = Convert.ToInt32(textBox1.Text);
label1.Text = "Before conversion : " + num.GetType();
String str = Convert.ToString(num);
label2.Text = "After conversion: " + str.GetType();
}
private void button2_Click(object sender, EventArgs e)
{
label1.Text = "Before conversion : " + textBox1.Text.GetType();
int num = Convert.ToInt32(textBox1.Text);
label2.Text = "After conversion: " + num.GetType();
}
}
}
:
B) Write ASP.Net program to connect to the master database in SQL Server in the
Page_Load event. When the connection is established, the message “Connection has
been established” should be displayed in a label in the form .
Slip 11
A) Write a ASP.Net program that gets user input such as the user name, mode of
payment, appropriate credit card. After the user enters the appropriate values the
Validation button validates the values entered.
Answer :
:
B) Write C# program to make a class named Fruit with a data member to calculate the
number of fruits in a basket. Create two other class named Apples and Mangoes to
calculate the number of apples and mangoes in the basket. Display total number of
fruits in the basket.
Answer :
Slip 12
A) Write ASP.Net program that displays a button in green color and it should change
into yellow when the mouse moves over it.
Answer :
:
B) Write a VB.NET program to create player table (PID, PName, Game,
no_of_matches). Insert records and update number of matches of ‘Rohit Sharma’ and
display result in data grid view.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\player.accdb")
Dim adpt As New OleDbDataAdapter("Select * from player", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "player")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "player"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into player values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "'," & TextBox4.Text & ")"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "UPDATE player SET no_of_matches = " & TextBox4.Text & " WHERE PName = '" & TextBox2.Text & "'"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Updated Successfully...!")
End If
con.Close()
con.Close()
ds.Clear()
display()
End Sub
End Class
Slip 13
A) Write a VB.net program for blinking an image.
Answer :
Public Class Form1
Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles Timer1.Tick
If PictureBox1.Visible Then
PictureBox1.Visible = False
Else
PictureBox1.Visible = True
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Interval = 1000
Timer1.Start()
End Sub
End Class
:
B) Write a C# Program to accept and display ‘n’ student’s details such as Roll. No,
Name, marks in three subjects, using class. Display percentage of each student.
Answer :
Slip 14
A) Write a program in C#.Net to find the sum of all elements of the array.
Answer :
namespace WinFormsApp27
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
int a,b=0,c;
for(int i = 0; i < listBox1.Items.Count; i++)
{
a = Convert.ToInt32(listBox1.Items[i]);
c = a + b;
b = c;
}
MessageBox.Show("Addtion is : " + b);
}
}
}
:
B) Write a C#.Net Program to define a class Person having members –name, address.
Create a subclass called employee with member staffed, salary. Create ‘n’ objects of the
Employee class and display all the details of the Employee.
Answer :
Slip 15
A) Write ASP.Net application to create a user control that contains a list of colors. Add
a button to the Web Form which when clicked changes the color of the form to the
color selected from the list.
Answer :
Public Class Form1
Private Sub RedToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RedToolStripMenuItem.Click
Me.BackColor = Color.Red
End Sub
Private Sub GreenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GreenToolStripMenuItem.Click
Me.BackColor = Color.Green
End Sub
Private Sub BlueToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BlueToolStripMenuItem.Click
Me.BackColor = Color.Blue
End Sub
End Class
:
B) Write a C#.Net Program to accept and display ‘n’ customer’s details such as
customer_no, Name, address ,itemno, quantity price . Display total price of all item.
Slip 16
A) Write ASP.Net program to create a user control that receives the user name and
password from the user and validates them. If the user name is "DYP" and the password
is "Pimpri", then the user is authorized, otherwise not.
Answer :
:
B) Define a class supplier with fields – sid, name, address, pincode. Write a C#.Net
Program to accept the details of ‘n’ suppliers and display it.
Answer :
Slip17
A) Write a C#.Net application to display the vowels from a given String.
Answer :
namespace WinFormsApp21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String str = (textBox1.Text);
char[] chars = str.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
switch (chars[i])
{
case 'A' or 'a':
listBox1.Items.Add(chars[i].ToString());
break;
case 'E' or 'e':
listBox1.Items.Add(chars[i].ToString());
break;
case 'I' or 'i':
listBox1.Items.Add(chars[i].ToString());
break;
case 'O' or 'o':
listBox1.Items.Add(chars[i].ToString());
break;
case 'U' or 'u':
listBox1.Items.Add(chars[i].ToString());
break;
}
}
}
}
}
:
B) 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 data grid view.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\product.accdb")
Dim adpt As New OleDbDataAdapter("Select * from product", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "product")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "product"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into product values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & DateTimePicker1.Value & "'," & TextBox4.Text & ")"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
End Class
Slip 18
A) Write a VB.NET program to accept a number from user through input box and
display its multiplication table into the list box.
Answer :
Public Class Form1
Dim a As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As Integer
a = TextBox1.Text
For b = 1 To 10
ListBox1.Items.Add(a * b)
Next
Console.ReadLine()
End Sub
End Class
:
B) Write ASP.Net program containing the following controls:
• ListBox
• Button
• Image
• Label
The listbox is used to list items available in a store. When the user clicks on an
item in the listbox, its image is displayed in the image control. When the user clicks the
button, the cost of the selected item is displayed in the control.
Answer :
Slip 19
A) Write a VB.NET program to check whether enter string is palindrome or not.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str, rev As String
str = TextBox1.Text
rev = StrReverse(str)
If (str = rev) Then
MessageBox.Show("String is Palindrome : " & str)
Else
MessageBox.Show("String is Not Palindrome : " & str)
End If
End Sub
End Class
:
B) "How is the book ASP.NET with C# by Wrox publication?"
Give the user three choices :
i)Good ii)Satisfactory iii)Bad.
Provide a VOTE button. After user votes, present the result in percentage using labels
next to the choices.
Answer :
Slip 20
A) Write a VB.NET program to generate Sample Tree View control.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TreeView1.Nodes.Add("Master")
TreeView1.Nodes(0).Nodes.Add("Student Details")
TreeView1.Nodes(0).Nodes.Add("Teacher Details")
TreeView1.Nodes.Add("Examination")
TreeView1.Nodes(1).Nodes.Add("Internal Exam")
TreeView1.Nodes(1).Nodes.Add("External Exam")
TreeView1.Nodes(1).Nodes.Add("Practical Exam")
End Sub
End Class
:
B) Write a Web application in ASP.Net that generates the “IndexOutOfRange”
exception when a button is clicked. Instead of displaying the above exception, it
redirects the user to a custom error page. All the above should be done with the trace
for the page being enabled.
Answer :
Slip 21
A) Write a VB.NET program to accept sentences in text box and count the number of
words and display the count in message box.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String
str = TextBox1.Text
Dim I, Count As Integer
Dim arr() As Char = str.ToCharArray
For I = 0 To arr.Length - 1
If arr(I) = " " Then
Count = Count + 1
End If
Next
MsgBox(Count + 1 & " words")
End Sub
End Class
:
B) Write ASP.Net application for the following:
1. Create a table EMP(eno, ename, edesignation, salary, joindate)
2. Insert a Record.
3. Update a record
Answer :
Slip 22
A) Write a program in C# to create a function to swap the values of two integers.
Answer :
:
B) Write a Vb.net program to design the following form; it contains the three menus
Color (Red, Blue, and Green), Window (Maximize, Minimize, and Restore) and Exit.
On Selection of any menu or submenu result should affect the form control( for
example if user selected Red color from Color menu back color of form should get
changed to Red and if user selected Maximize from Window Menu then form should
get maximized).
Answer :
Public Class Form1
Private Sub RedToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RedToolStripMenuItem.Click
Me.BackColor = Color.Red
End Sub
Private Sub GreenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GreenToolStripMenuItem.Click
Me.BackColor = Color.Green
End Sub
Private Sub BlueToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BlueToolStripMenuItem.Click
Me.BackColor = Color.Blue
End Sub
Private Sub MaximizeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MaximizeToolStripMenuItem.Click
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub MiniMToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MiniMToolStripMenuItem.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub RestoreToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RestoreToolStripMenuItem.Click
Me.WindowState = FormWindowState.Normal
End Sub
End Class
Slip 23
A) Write a program in C# to create a function to display the n terms of Fibonacci
sequence.
Answer :
namespace WinFormsApp22
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a, b=0, c=1, d;
a = Convert.ToInt32(textBox1.Text);
listBox1.Items.Add(b);
listBox1.Items.Add(c);
for (int i = 0; i < a; i++)
{
d = b + c;
listBox1.Items.Add(d);
b = c;
c = d;
}
}
}
}
:
B) Create the application in ASP.Net that accepts name, password ,age , email id, and
user id. All the information entry is compulsory. Password should be reconfirmed. Age
should be within 21 to 30. Email id should be valid. User id should have at least a
capital letter and digit as well as length should be between 7 and 20 characters.
Answer :
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="validationinasp._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<main>
<table style="width: 66%;">
<tr>
<td class="style1" colspan="3" align="center">
<asp:Label ID="lblmsg"
Text="Registration Form"
runat="server" />
</td>
</tr>
<tr>
<td class="style3">
Candidate:
</td>
<td class="style2">
<asp:DropDownList ID="ddlcandidate" runat="server" style="width:239px">
<asp:ListItem>Please Choose a Candidate</asp:ListItem>
<asp:ListItem>M H Kabir</asp:ListItem>
<asp:ListItem>Steve Taylor</asp:ListItem>
<asp:ListItem>John Abraham</asp:ListItem>
<asp:ListItem>Venus Williams</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvcandidate"
runat="server" ControlToValidate ="ddlcandidate"
ErrorMessage="Please choose a candidate"
InitialValue="Please choose a candidate">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
House:
</td>
<td class="style2">
<asp:RadioButtonList ID="rblhouse" runat="server" RepeatLayout="Flow">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Yellow</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvhouse" runat="server"
ControlToValidate="rblhouse" ErrorMessage="Enter your house name" >
</asp:RequiredFieldValidator>
<br />
</td>
</tr>
<tr>
<td class="style3">
Class:
</td>
<td class="style2">
<asp:TextBox ID="txtclass" runat="server"></asp:TextBox>
</td>
<td>
<asp:RangeValidator ID="rvclass"
runat="server" ControlToValidate="txtclass"
ErrorMessage="Enter your class (6 - 12)" MaximumValue="12"
MinimumValue="6" Type="Integer">
</asp:RangeValidator>
</td>
</tr>
<tr>
<td class="style3">
Email:
</td>
<td class="style2">
<asp:TextBox ID="txtemail" runat="server" style="width:250px">
</asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator ID="remail" runat="server"
ControlToValidate="txtemail" ErrorMessage="Enter your email"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style3" style="height: 21px">
Password:</td>
<td class="style2" style="height: 21px">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox></td>
<td style="height: 21px">
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator"
ControlToCompare="TextBox2" ControlToValidate="TextBox3">*password must match with confirm password</asp:CompareValidator></td>
</tr>
<tr>
<td class="style3" style="height: 21px">
Confirm Password:</td>
<td class="style2">
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox></td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3" style="height: 21px">
Name:</td>
<td class="style2">
<asp:TextBox ID="TextBox4" runat="server" ></asp:TextBox> </td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Name is required"
ControlToValidate="TextBox4">*Name is required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmail"
ValidationExpression="^[a-zA-Z]*$" ControlToValidate="TextBox4"
runat="server">enter only alphabets</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style3" style="height: 21px">
Enter Number</td>
<td class="style2">
<asp:TextBox ID="TextBox8" runat="server" ></asp:TextBox> </td> </td>
<td>
</td>
</tr>
<tr>
<td class="style3" style="height: 21px">
</td>
<td class="style2">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style3" align="center" colspan="3">
</td>
</tr>
</table>
</main>
</asp:Content>
Slip 24
A) Write a program in C#.Net to create a function to check whether a number is prime or
not.
Answer :
namespace WinFormsApp26
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static String prime(int a)
{
Boolean isprime = true;
int b = a/2;
for(int i = 2; i <= b; i++)
{
if(a % 2 == 0)
{
isprime = false;
break;
}
}
if (isprime)
{
return a + " is Prime Number";
}
else
{
return a + " is Not Prime Number";
}
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(prime(Convert.ToInt32(textBox1.Text)));
}
}
}
:
B) Write a VB.NET program to create Author table (aid, aname, book_ name). Insert the
records (Max 5). Delete a record of author who has written “VB.NET book” and
display remaining records on the data grid view. (Use MS Access to create db.)
Answer :
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\Author.accdb")
Dim adpt As New OleDbDataAdapter("Select * from Author", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "Author")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Author"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into Author values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "')"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "DELETE FROM Author WHERE book_name='" & TextBox3.Text & "'"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Deleted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
End Class
Slip 25
A) Write a program in C#.Net to create a function to calculate the sum of the individual
digits of a given number.
Answer :
:
B) Create a Web Application in ASP.Net to display all the Empname and Deptid of the
employee from the database using SQL source control and bind it to GridView.
Database fields are(DeptId, DeptName, EmpName, Salary).
Create Table Alter Table Drop Table Type Your DDL Query Here
Answer :
Slip 26
A). Write a program in C#.Net to create a recursive function to find the factorial of a
given number
Answer :
:
B) Write a ASP.Net program to create a Login Module which adds Username and
Password in the database. Username in the database should be a primary key.
Answer :
Slip 27
A) Write a program in C#.Net to find the length of a string.
Answer :
namespace WinFormsApp24
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a = textBox1.Text.Length;
MessageBox.Show("Length : " + a);
}
}
}
:
B) Create a web application in ASP.Net which may have a textbox. Now user must type
some data into it, the data he can enter is only 255 characters. After he crosses the limit
then the last word should not by typed and at the same time color of textbox
should be red.
Slip 28
A) Write a program in C#.Net to read n numbers in an array and display it in reverse
order.
Answer :
namespace WinFormsApp23
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
listBox2.Items.Clear();
for (int i = listBox1.Items.Count-1; i >= 0; i--)
{
listBox2.Items.Add (listBox1.Items[i]);
}
}
}
}
:
B) Write a VB.NET program to create a table Patient (PID, PName, Contact No,
Disease). Insert five records into table and display appropriate message in message box.
ENo EName Salary
Slip 29
A) Write a program in C#.Net to separate the individual characters from a String.
Answer :
using System;
class Program {
static void Main(string[] args) {
string inputString = "Hello, world!";
char[] characters = inputString.ToCharArray();
Console.WriteLine("Individual characters from the string: ");
foreach (char c in characters) {
Console.Write(c + " ");
}
Console.ReadLine();
}
}
:
B) Write a VB.NET program to accept the details of customer (CName, Contact No,
Email_id). Store it into the database with proper validation and display appropriate
message by using Message box.
Answer :
Imports System.Data.SqlClient
Public Class CustomerForm
' Database connection string
Dim connectionString As String = "Data Source=localhost\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=True"
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
' Get the customer details from textboxes
Dim cname As String = txtName.Text.Trim()
Dim contactNo As String = txtContactNo.Text.Trim()
Dim email As String = txtEmail.Text.Trim()
' Validate the inputs
If cname = "" Then
MessageBox.Show("Please enter customer name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
If contactNo = "" Or Not IsNumeric(contactNo) Then
MessageBox.Show("Please enter valid contact number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
If email = "" Or Not email.Contains("@") Then
MessageBox.Show("Please enter valid email address.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
' Insert the customer details into the database
Using connection As New SqlConnection(connectionString)
Dim query As String = "INSERT INTO Customers (CName, ContactNo, Email) VALUES (@CName, @ContactNo, @Email)"
Dim command As New SqlCommand(query, connection)
command.Parameters.AddWithValue("@CName", cname)
command.Parameters.AddWithValue("@ContactNo", contactNo)
command.Parameters.AddWithValue("@Email", email)
connection.Open()
Dim rowsAffected As Integer = command.ExecuteNonQuery()
connection.Close()
If rowsAffected > 0 Then
MessageBox.Show("Customer details saved successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Failed to save customer details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Using
End Sub
End Class
Slip 30
A) Write a VB.NET program to design following screen, accept the details from the user. Clicking on Submit button Net Salary should be calculated and displayed into the Textbox. Display the Messagebox informing the Name and Net Salary of employee.
Answer :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label10.Text = (Int(TextBox2.Text) + Int(TextBox3.Text) + Int(TextBox4.Text) + Int(TextBox5.Text) + Int(TextBox6.Text) + Int(TextBox7.Text) + Int(TextBox8.Text))
Label12.Text = Int(TextBox6.Text) + Int(TextBox7.Text) + Int(TextBox8.Text)
Label14.Text = Label10.Text - Label12.Text
MessageBox.Show("Employee Name : " & TextBox1.Text & Environment.NewLine & "Total Salary is : " & Label14.Text)
End Sub
Private Sub TextBox2_Leave(sender As Object, e As EventArgs) Handles TextBox2.Leave
TextBox3.Text = (TextBox2.Text * 31) / 100
TextBox4.Text = (TextBox2.Text * 9) / 100
End Sub
End Class
:
B) Write a VB.NET program to accept the details Supplier (SupId, SupName, Phone
No, Address) store it into the database and display it.
Answer :
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Saurabh\Desktop\New folder\Supplier.accdb")
Dim adpt As New OleDbDataAdapter("Select * from Supplier", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "Supplier")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Supplier"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into Supplier values(" & TextBox1.Text & ",'" & TextBox2.Text & "'," & TextBox3.Text & ",'" & TextBox4.Text & "')"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
End Class
Please upload tybca all practice silp
ReplyDeleteSir please provide the t.y.b.c.a sem 6th practical slips with solutions
ReplyDelete