C# RECORD Updated
C# RECORD Updated
12. Program to validate the given user credentials with default values 54-55
13. Implementing student registration form and displaying given inputs in the browser when submit 56-59
button is clicked
14. Write the procedure to deploy ASP.NET application In IIS (descriptive) 60-63
15. a) ASP.NET program to display grid view content with database connectivity 64-66
b) Write the steps to connect the database to the grid view
16. ASP.NET program to open the respective webform when a particular menu item is selected 67-70
1
//1) arithmetic operations
using System;
class ArithemeticOperations
int a, b, result;
a=Convert.ToInt32(Console.ReadLine());
b=Convert.ToInt32(Console.ReadLine());
result=a+b;
Console.WriteLine("Sum is "+result);
result=a-b;
Console.WriteLine("Difference is "+result);
result=a*b;
Console.WriteLine("Product is "+result);
result=a/b;
Console.WriteLine("Division is "+result);
result=a%b;
Console.WriteLine("Remainder is "+result);
2
3
// 2) multiplication table generation
using System;
int j,n;
Console.Write("\n\n");
Console.Write("-----------------------------------");
Console.Write("\n\n");
n= Convert.ToInt32(Console.ReadLine());
Console.Write("\n");
for(j=1;j<=10;j++)
4
// 3) Sorting of given strings in ascending order
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
class Program
string[] a;
string temp;
int n,i,j,l;
n= Convert.ToInt32(Console.ReadLine());
a=new string[n];
for(i=0;i<n;i++)
a[i] = Console.ReadLine();
l=a.Length;
5
{
temp = a[j];
a[j + 1] = temp;
6
// 4) Implementing matrix multiplication
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
class Matrix
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
a[i,j]=Convert.ToInt32(Console.ReadLine());
for(i=0;i<3;i++)
for(j=0;j<3;j++)
Console.Write(a[i,j]+"\t");
Console.WriteLine();
7
}
8
// 5) Checking if the given number is prime or not
using System;
namespace Demo
class PrimeNumber
int n, a = 0;
n = Convert.ToInt32(Console.ReadLine());
if (n % i == 0)
a++;
if (a == 2)
else
Console.ReadLine();
9
}
10
// 6) Login form creation and validation
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace login_form
public Form1()
InitializeComponent();
this.Close();
11
attempt = 0;
label4.Text = ("You Have Only " + Convert.ToString(attempt) + " Attempt Left To Try");
--attempt;
else
12
13
// 7) Performing basic calculator operations
using System;
namespace Calculator
public Form1()
InitializeComponent();
}
14
private void zero_Click(object sender, EventArgs e)
this.textBox1.Text = "";
input +="0";
this.textBox1.Text += input;
this.textBox1.Text = "";
input += "1";
this.textBox1.Text += input;
this.textBox1.Text = "";
input += "2";
this.textBox1.Text += input;
this.textBox1.Text = "";
input += "3";
this.textBox1.Text += input;
this.textBox1.Text = "";
input += "4";
15
this.textBox1.Text += input;
this.textBox1.Text = "";
input += "5";
this.textBox1.Text += input;
this.textBox1.Text = "";
input += "6";
this.textBox1.Text += input;
this.textBox1.Text = "";
input += "7";
this.textBox1.Text += input;
this.textBox1.Text = "";
input += "8";
this.textBox1.Text += input;
this.textBox1.Text = "";
16
input += "9";
this.textBox1.Text += input;
this.textBox1.Text = "";
input += ".";
this.textBox1.Text += input;
input = string.Empty;
input = string.Empty;
operand1 = input;
operation = '+';
input = string.Empty;
17
input = string.Empty;
this.textBox1.Text = "";
this.input = string.Empty;
this.operand1 = string.Empty;
this.operand2 = string.Empty;
operand2 = input;
double.TryParse(operand1,out
if(operation=='+')
textBox1.Text = result.ToString();
else if(operation=='-')
textBox1.Text = result.ToString();
else if(operation=='*')
18
result = num1 * num2;
textBox1.Text = result.ToString();
else if(operation=='/')
if(num2!=0)
textBox1.Text = result.ToString();
else
textBox1.Text = "div/zero!";
OUTPUT: -
Input1
19
Operation
Input2 Equals
20
// 8) Accept student registration details and copy them in RichTextBox
namespace registration
public Form1()
InitializeComponent();
{
21
string gender; int total;
if(radioButton1.Checked==true)
gender = radioButton1.Text;
} else {
gender = radioButton2.Text;
} int a, b, c;
a = Convert.ToInt32(textBox5.Text); b=
Convert.ToInt32(textBox6.Text); c=
Convert.ToInt32(textBox7.Text); total = a + b + c;
this.Close();
22
}
OUTPUT:
Entering details
23
// 9) MDI form implementation
//MDI Form
Design
Coding
using System;
namespace MDI
public Form1()
InitializeComponent();
Form2 f2;
Form3 f3;
if(f2==null) {
} else {
f2.Activate();
if(f3==null) {
} else {
f3.Activate();
25
}
OUTPUT:
26
// 10) Implementing student login validation using backend database (ADO.NET)
27
Steps for creating a database table for student details
Start-All programs-Microsoft SQL Server 2016
Open Microsoft SQL Server Management
Login with the user credentials
After connecting to the SQL server right click on the database and create a new database
Right click on the table and create a new table with the details as follows
28
Coding Form1
using System;
namespace windows_form
{ public Form1()
InitializeComponent();
29
cmd.Parameters.AddWithValue("a", textBox1.Text.ToString()); cmd.Parameters.AddWithValue("b",
textBox2.Text.ToString()); cmd.Parameters.AddWithValue("c", textBox3.Text.ToString());
cmd.Parameters.AddWithValue("d", textBox4.Text.ToString()); cmd.ExecuteNonQuery();
this.Close();
Form2
using System;
namespace windows_form
public Form2()
InitializeComponent();
30
private void button1_Click(object sender, EventArgs e) {
string st="select count(*) from info where rollno='"+textBox1.Text+"'"; SqlCommand cmd = new
SqlCommand(st, con); int x = Convert.ToInt32( cmd.ExecuteScalar()); if(x==0)
{
} else {
string q = "update info set name='" + textBox2.Text + "', phone='" + textBox3.Text + "'," +
con.Close();
this.Close();
Form3
using System;
31
using System.Collections.Generic; using
System.ComponentModel; using System.Data; using
System.Drawing; using System.Linq; using
System.Text; using System.Threading.Tasks; using
System.Windows.Forms; using
System.Data.SqlClient;
namespace windows_form
public Form3()
InitializeComponent();
string x, y, z;
x = sdr["name"].ToString(); y=
sdr["phone"].ToString(); z = sdr["address"].ToString();
textBox2.Text = x; textBox3.Text = y;
textBox4.Text = z;
this.Close();
Form5
using System;
namespace windows_form
33
public Form5()
InitializeComponent();
string q1 = "select name,phone,address from info where rollno=' " + textBox1.Text.ToString() + "'";
if (sdr.Read() == true)
string x, y, z;
x = sdr["name"].ToString(); y=
sdr["phone"].ToString(); z = sdr["address"].ToString();
textBox2.Text = x; textBox3.Text = y;
textBox4.Text = z;
MessageBox.Show("Record found....");
} else
this.Close();
}
34
}
Form4
using System;
namespace windows_form
public Form4()
InitializeComponent();
Form1 insert;
Form2 update;
Form3 delete;
Form5 search;
if(insert==null)
} else {
insert.Activate();
35
}
if (update == null)
} else {
update.Activate();
if(delete==null)
} else {
delete.Activate();
if (search == null)
} else {
search.Activate();
36
}
this.Close();
namespace windows_form
/// <summary>
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form4());
}
37
OUTPUT:
38
39
// 11) Menu strip program to open the respective form for the selected menu item
using System;
namespace LOGIN_MENU_PROGRAM
public Form1()
InitializeComponent();
Close();
nForm.Show(); }
nForm.Show(); }
nForm.Show(); }
nForm.Show(); }
41
using System;
namespace LOGIN_MENU_PROGRAM
public INSERT()
InitializeComponent();
Close();
42
textBox1.Text = ""; textBox2.Text = "";
textBox3.Text = ""; }
if (sdr.Read() == true)
else {
sdr.Close();
command.ExecuteNonQuery();
con.Close();
43
using System;
public UPDATE()
InitializeComponent();
if (x == 0)
} else
if (sdr.Read() == true)
{ string x1;
cmd2.ExecuteNonQuery();
textBox4.Text + "");
con.Close();
} }
45
{
Close();
using System;
public DELETE()
InitializeComponent();
46
{
Close();
if (sdr.Read() == true)
{ string x;
x = sdr["name"].ToString(); textBox3.Text = x;
sdr.Close();
} else
47
namespace LOGIN_MENU_PROGRAM
/// </summary>
private System.ComponentModel.IContainer components = null;
/// </summary>
/// <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>
components.Dispose();
/// </summary>
private void InitializeComponent()
this.loginBindingSource = new
System.Windows.Forms.BindingSource(this.components);
this.loginTableAdapter = new
LOGIN_MENU_PROGRAM.studentDataSet1TableAdapters.loginTableAdapter();
this.useridDataGridViewTextBoxColumn = new
System.Windows.Forms.DataGridViewTextBoxColumn();
this.nameDataGridViewTextBoxColumn = new
System.Windows.Forms.DataGridViewTextBoxColumn();
(( System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
(( System.ComponentModel.ISupportInitialize)(this.loginBindingSource)).BeginInit();
(( System.ComponentModel.ISupportInitialize)(this.studentDataSet)).BeginInit();
(( System.ComponentModel.ISupportInitialize)(this.studentDataSet1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.loginBindingSource1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
49
this.dataGridView1.AutoGenerateColumns = false; this.dataGridView1.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new
System.Windows.Forms.DataGridViewColumn[] { this.useridDataGridViewTextBoxColumn,
this.password,
this.nameDataGridViewTextBoxColumn});
this.dataGridView1.TabIndex = 0;
//
// loginBindingSource
//
this.loginBindingSource.DataMember = "login";
this.loginBindingSource.DataSource = this.studentDataSet;
//
// studentDataSet
//
System.Data.SchemaSerializationMode.IncludeSchema;
//
// loginTableAdapter
//
this.loginTableAdapter.ClearBeforeFill = true;
//
// studentDataSet1
//
//
// loginBindingSource1
//
this.loginBindingSource1.DataMember = "login";
this.loginBindingSource1.DataSource = this.studentDataSet1;
//
// loginTableAdapter1
//
this.loginTableAdapter1.ClearBeforeFill = true;
//
// useridDataGridViewTextBoxColumn
//
this.useridDataGridViewTextBoxColumn.DataPropertyName = "userid";
this.useridDataGridViewTextBoxColumn.HeaderText = "userid";
this.useridDataGridViewTextBoxColumn.Name =
"useridDataGridViewTextBoxColumn";
//
// password
//
//
// nameDataGridViewTextBoxColumn
//
this.nameDataGridViewTextBoxColumn.DataPropertyName = "name";
this.nameDataGridViewTextBoxColumn.HeaderText = "name";
this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn";
//
// VIEW
51
//
this.Controls.Add(this.dataGridView1);
(( System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
(( System.ComponentModel.ISupportInitialize)(this.loginBindingSource)).EndInit();
(( System.ComponentModel.ISupportInitialize)(this.studentDataSet)).EndInit();
(( System.ComponentModel.ISupportInitialize)(this.studentDataSet1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.loginBindingSource1)).EndInit();
this.ResumeLayout(false); } #endregion
nameDataGridViewTextBoxColumn;
52
53
// 12) Program to validate the given user credentials with default values
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication6
else
54
Response.Write("INVALID ID AND PASSWORD");
TextBox1.Text=” ”;
TextBox2.Text=” “;
55
// 13) Implementing student registration form and displaying given inputs in the browser when submit button is
clicked
// Implementation of web form to display student registration details given in ASP.NET to display the given input in the
browser when Submit button clicked.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
if (!IsPostBack)
BindDatalist();
56
}
ds.ReadXml(xmlreader);
xmlreader.Close();
if (ds.Tables.Count != 0)
DataList1.DataSource = ds;
DataList1.DataBind();
else
DataList1.DataSource = null;
DataList1.DataBind();
xmldoc.Load(Server.MapPath("Sample.xml"));
BindDatalist();
string sex;
if(RadioButton1.Checked==true)
sex = RadioButton1.Text;
57
}
else
sex = RadioButton2.Text;
xmldoc.Load(Server.MapPath("Sample.xml"));
name.InnerText = TextBox1.Text;
Roll_No.InnerText = TextBox2.Text;
Course.InnerText = DropDownList1.SelectedItem.Text;
Gender.InnerText = sex;
Email.InnerText = TextBox3.Text;
Phone_no.InnerText = TextBox4.Text;
parentelement.AppendChild(name);
parentelement.AppendChild(Roll_No); 46
parentelement.AppendChild(Course);
parentelement.AppendChild(Gender);
parentelement.AppendChild(Email);
parentelement.AppendChild(Phone_no);
xmldoc.DocumentElement.AppendChild(parentelement);
xmldoc.Save(Server.MapPath("Sample.xml"));
BindDatalist();
}
58
protected void Button3_Click(object sender, EventArgs e)
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
DropDownList1.Text = "";
RadioButton1.Checked = false;
RadioButton2.Checked = false;
59
// 14) Write the procedure to deploy ASP.NET application In IIS (descriptive)
Now in the top we have the option Build. Click on that and under Build you will find Publish Website.
For Target location specify where to save your web application DLL file.
60
Then click on publish.
Go to the target folder and in that location, you will see your web application DLL file.
Enter Alias name then select an Application pool and Physical path.
61
Now Double-click on default document.
And add a start page of your web application. Here my application start page is EstimationSlip.aspx.
62
Now right-click on your application and browse.
63
// 15) a) ASP.NET program to display grid view content with database connectivity
// Program to implement grid view property of a table extracting from ADO.NET using windows forms
64
Step 3: Selecting data table columns to display in gridview.
65
Step 5: Debugging the Grid_View for final data connectivity with ASP.NET form and display content in a browser.
66
// 16) ASP.NET program to open the respective webform when a particular menu item is selected
// ASP.NET MENU PROGRAM OUTPUT FOR MENU OPTIONS USAGE USING ASP.NET AND ADO.NET
FACILITY
67
Step 3: Selected Insert record menu option
68
Step 6: View menu option selected result.
// MENU PROGRAM IN ASP.NET USING DATA CONNECTIVITY FROM SQL SERVER DATA SOURCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
69
}
70