0% found this document useful (0 votes)
52 views70 pages

C# RECORD Updated

1) The document contains an index listing various programming topics and their corresponding page numbers covering console applications, Windows Forms, and ASP.NET. 2) The topics for console applications include arithmetic operations, multiplication table generation, sorting strings, matrix multiplication, and checking prime numbers. 3) The Windows Forms topics cover creating a login form with validation, basic calculator operations, student registration, MDI forms, and database integration. 4) The ASP.NET topics include user validation, a student registration form, deploying to IIS, grid views with databases, and menu navigation between forms.

Uploaded by

rlmahanthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views70 pages

C# RECORD Updated

1) The document contains an index listing various programming topics and their corresponding page numbers covering console applications, Windows Forms, and ASP.NET. 2) The topics for console applications include arithmetic operations, multiplication table generation, sorting strings, matrix multiplication, and checking prime numbers. 3) The Windows Forms topics cover creating a login form with validation, basic calculator operations, student registration, MDI forms, and database integration. 4) The ASP.NET topics include user validation, a student registration form, deploying to IIS, grid views with databases, and menu navigation between forms.

Uploaded by

rlmahanthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

INDEX

S.No Description Pg.No


Console applications

1. Arithmetic operations 2-3


2. Multiplication table generation 4
3. Sorting of given strings in ascending order 5-6
4. Implementing matrix multiplication 7-8
5. Checking if the given number is prime or not 9-10
Windows Forms

6. Login form creation and validation 11-13


7. Performing basic calculator operations 14-20
8. Accept student registration details and copy them in RichTextBox 21-23
9. MDI form implementation 24-26
10. Implementing student login validation using backend database (ADO.NET) 27-39
11. Menu strip program to open the respective form for the selected menu item 40-53
ASP.NET

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

// arithmetic operations using console input

using System;

class ArithemeticOperations

static void Main()

int a, b, result;

Console.WriteLine("Enter value of a : ");

a=Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter value of b : ");

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;

public class MultiplicationTable

public static void Main()

int j,n;

Console.Write("\n\n");

Console.Write("Display the multiplication table:\n");

Console.Write("-----------------------------------");

Console.Write("\n\n");

Console.Write("Input the number (Table to be calculated) : ");

n= Convert.ToInt32(Console.ReadLine());

Console.Write("\n");

for(j=1;j<=10;j++)

Console.Write("{0} X {1} = {2} \n",n,j,n*j);

4
// 3) Sorting of given strings in ascending order

// sorting of strings in ascending order(alphabetical order)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApp1

class Program

static void Main(string[] args)

string[] a;

string temp;

int n,i,j,l;

Console.Write("Enter number of strings to be printed :");

n= Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter the strings : ");

a=new string[n];

for(i=0;i<n;i++)

a[i] = Console.ReadLine();

l=a.Length;

for (i = 0; i < l; i++)

for (j = 0; j < l-1; j++)

5
{

if (a[j].CompareTo(a[j + 1]) > 0)

temp = a[j];

a[j] = a[j + 1];

a[j + 1] = temp;

Console.Write("After sorting the array appears like : \n");

for (i = 0; i < l; i++)

Console.WriteLine(a[i] + " ");

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

static void Main(string[] args)

int [,] a=new int[3,3];

int i,j;

Console.WriteLine("Enter 2 dimensional array elements");

for(i=0;i<3;i++)

for(j=0;j<3;j++)

a[i,j]=Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Given 2 dimensional array elements are :");

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

public static void Main()

int n, a = 0;

Console.WriteLine("Enter a number to check if it is Prime or not :");

n = Convert.ToInt32(Console.ReadLine());

for (int i = 2; i <= n/2; i++)

if (n % i == 0)

a++;

if (a == 2)

Console.WriteLine("{0} is a Prime Number", n);

else

Console.WriteLine("Not a Prime Number");

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 partial class Form1 : Form

static int attempt = 3;

public Form1()

InitializeComponent();

private void button2_Click(object sender, EventArgs e)

this.Close();

private void button1_Click(object sender, EventArgs e)

string username = textBox1.Text;

string password = textBox2.Text;

if ((this.textBox1.Text == "Admin") && (this.textBox2.Text == "admin"))

11
attempt = 0;

pictureBox1.Image = new Bitmap(@"C:\Users\Mic 18\Desktop\granted.jpg");

MessageBox.Show("you are granted with access");

else if ((attempt == 3) && (attempt > 0))

pictureBox1.Image = new Bitmap(@"C:\Users\Mic 18\Desktop\images1.jpg");

label4.Text = ("You Have Only " + Convert.ToString(attempt) + " Attempt Left To Try");

--attempt;

else

pictureBox1.Image = new Bitmap(@"C:\Users\Mic 18\Desktop\denied.jpg");

MessageBox.Show("you are not granted with access");

12
13
// 7) Performing basic calculator operations

//Program to perform operations in Calculator using windows form.

Designing the calculator in windows form

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 Calculator

public partial class Form1 : Form

string input = string.Empty; string operand1 =


string.Empty; string operand2 = string.Empty;
char operation;

double result = 0.0;

public Form1()

InitializeComponent();

}
14
private void zero_Click(object sender, EventArgs e)

this.textBox1.Text = "";

input +="0";

this.textBox1.Text += input;

private void one_Click(object sender, EventArgs e)

this.textBox1.Text = "";

input += "1";

this.textBox1.Text += input;

private void two_Click(object sender, EventArgs e)

this.textBox1.Text = "";

input += "2";

this.textBox1.Text += input;

private void three_Click(object sender, EventArgs e)

this.textBox1.Text = "";

input += "3";

this.textBox1.Text += input;

private void four_Click(object sender, EventArgs e)

this.textBox1.Text = "";

input += "4";
15
this.textBox1.Text += input;

private void five_Click(object sender, EventArgs e)

this.textBox1.Text = "";

input += "5";

this.textBox1.Text += input;

private void six_Click(object sender, EventArgs e)

this.textBox1.Text = "";

input += "6";

this.textBox1.Text += input;

private void seven_Click(object sender, EventArgs e)

this.textBox1.Text = "";

input += "7";

this.textBox1.Text += input;

private void eight_Click(object sender, EventArgs e) {

this.textBox1.Text = "";

input += "8";

this.textBox1.Text += input;

private void nine_Click(object sender, EventArgs e)

this.textBox1.Text = "";

16
input += "9";

this.textBox1.Text += input;

private void dot_Click(object sender, EventArgs e)

this.textBox1.Text = "";

input += ".";

this.textBox1.Text += input;

private void divide_Click(object sender, EventArgs e)

operand1 = input; operation =


'/';

input = string.Empty;

private void star_Click(object sender, EventArgs e)

operand1 = input; operation = '*';

input = string.Empty;

private void plus_Click(object sender, EventArgs e)

operand1 = input;
operation = '+';

input = string.Empty;

private void minus_Click(object sender, EventArgs e)

operand1 = input; operation = '-';

17
input = string.Empty;

private void clear_Click(object sender, EventArgs e)

this.textBox1.Text = "";

this.input = string.Empty;

this.operand1 = string.Empty;

this.operand2 = string.Empty;

private void equals_Click(object sender, EventArgs e)

operand2 = input;

double num1, num2;

double.TryParse(operand1,out

num1); double.TryParse(operand2, out


num2);

if(operation=='+')

result = num1 + num2;

textBox1.Text = result.ToString();

else if(operation=='-')

result = num1 - num2;

textBox1.Text = result.ToString();

else if(operation=='*')

18
result = num1 * num2;

textBox1.Text = result.ToString();

else if(operation=='/')

if(num2!=0)

result = num1 / num2;

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

//Student Registration form


Design

Coding for buttons


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 registration

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void button2_Click(object sender, EventArgs e)

{
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;

richTextBox1.Text = "form inputs \n Name:" + textBox1.Text +

"\n Rollno:" + textBox2.Text +

"\n Dob:" + dateTimePicker1.Text +

"\n Gender:" + gender +

"\n Marks Secured:" + total +

"\n Course:" + comboBox1.Text +

"\n Email:" + textBox3.Text +

"\n Contact No:" + textBox4.Text;

private void button1_Click(object sender, EventArgs e)

richTextBox1.Text = ""; textBox1.Text = "";


textBox2.Text = ""; textBox3.Text = "";
textBox4.Text = ""; textBox5.Text = "";
textBox6.Text = ""; textBox7.Text = "";
comboBox1.Text = ""; radioButton1.Checked = false;
radioButton2.Checked = false;

private void button3_Click(object sender, EventArgs e)

this.Close();

22
}

OUTPUT:
Entering details

Getting details on rich textbox after submitting

23
// 9) MDI form implementation

//MDI Form
Design

Coding
using System;

using System.Collections.Generic; using


System.ComponentModel; using System.Data; using
System.Drawing; using System.Linq; using
24
System.Text; using System.Threading.Tasks; using
System.Windows.Forms;

namespace MDI

public partial class Form1 : Form

public Form1()

InitializeComponent();

Form2 f2;
Form3 f3;

private void redToolStripMenuItem_Click(object sender, EventArgs e)

if(f2==null) {

f2 = new Form2(); f2.Show();

} else {

f2.Activate();

private void greenToolStripMenuItem_Click(object sender, EventArgs e)

if(f3==null) {

f3 = new Form3(); f3.Show();

} else {

f3.Activate();

25
}

OUTPUT:

26
// 10) Implementing student login validation using backend database (ADO.NET)

//ADO.net program for student registration details


Design

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;

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 partial class Form1 : Form

{ public Form1()

InitializeComponent();

private void button1_Click(object sender, EventArgs e) {

SqlConnection con = new SqlConnection("Data Source=SAISURYA\\SAI;Initial

Catalog=student;Integrated Security=True"); con.Open();

string st = "insert into info values (@a,@b,@c,@d)"; SqlCommand cmd = new


SqlCommand(st, con);

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();

MessageBox.Show("record inserted"); con.Close();

private void button2_Click(object sender, EventArgs e)

textBox1.Text = ""; textBox2.Text = "";


textBox3.Text = ""; textBox4.Text = "";

private void button3_Click(object sender, EventArgs e)

this.Close();

Form2
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; using
System.Data.SqlClient;

namespace windows_form

{ public partial class Form2 : Form

public Form2()

InitializeComponent();

30
private void button1_Click(object sender, EventArgs e) {

SqlConnection con = new SqlConnection("Data Source=SAISURYA\\SAI;Initial

Catalog=student;Integrated Security=True"); con.Open();

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)
{

MessageBox.Show("Record doesn't exist!");

} else {

string q = "update info set name='" + textBox2.Text + "', phone='" + textBox3.Text + "'," +

"address='" + textBox4.Text + "' where rollno='" + textBox1.Text + "'";

SqlCommand cmd1 = new SqlCommand(q, con); cmd1.ExecuteNonQuery();

MessageBox.Show("Record updated succesfully...!");

con.Close();

private void button2_Click(object sender, EventArgs e)

textBox1.Text = ""; textBox2.Text = "";


textBox3.Text = ""; textBox4.Text = "";

private void button3_Click(object sender, EventArgs e)

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 partial class Form3 : Form

public Form3()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

SqlConnection con = new SqlConnection("Data Source=SAISURYA\\SAI;Initial

Catalog=student;Integrated Security=True"); con.Open();

string q = "select * from info where rollno='" + textBox1.Text + "'";

SqlCommand cmd = new SqlCommand(q, con); SqlDataReader


sdr = cmd.ExecuteReader(); 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;

int k = int.Parse(textBox1.Text); con.Close();

string q1 = "delete info where rollno = " + k + " "; con.Open();

SqlCommand command = new SqlCommand(q1, con); command.ExecuteNonQuery();

MessageBox.Show("Record Deleted Successfully.."); con.Close();


32
} else

MessageBox.Show("Record doesnot exist...");

private void button2_Click(object sender, EventArgs e)

textBox1.Text = ""; textBox2.Text = "";


textBox3.Text = ""; textBox4.Text = "";

private void button3_Click(object sender, EventArgs e)

this.Close();

Form5
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.Data.SqlClient; using
System.Windows.Forms;

namespace windows_form

public partial class Form5 : Form

33
public Form5()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

SqlConnection con = new SqlConnection("Data Source=SAISURYA\\SAI;Initial

Catalog=student;Integrated Security=True"); con.Open();

string q1 = "select name,phone,address from info where rollno=' " + textBox1.Text.ToString() + "'";

SqlCommand comm = new SqlCommand(q1, con);


SqlDataReader sdr = comm.ExecuteReader();

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;

//textBox2.Text = sdr[2].ToString(); //textBox3.Text=sdr[3];

MessageBox.Show("Record found....");

} else

MessageBox.Show("Record not found");

//SqlDataAdapter da = new SqlDataAdapter(comm); con.Close();

private void button3_Click(object sender, EventArgs e)

this.Close();

}
34
}

Form4
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 windows_form

public partial class Form4 : Form

public Form4()

InitializeComponent();

Form1 insert;

Form2 update;

Form3 delete;

Form5 search;

private void button1_Click(object sender, EventArgs e)

if(insert==null)

insert = new Form1(); insert.Show();

} else {

insert.Activate();

35
}

private void button2_Click(object sender, EventArgs e)

if (update == null)

update = new Form2(); update.Show();

} else {

update.Activate();

private void button3_Click(object sender, EventArgs e)

if(delete==null)

delete = new Form3(); delete.Show();

} else {

delete.Activate();

private void button4_Click(object sender, EventArgs e)

if (search == null)

search = new Form5(); search.Show();

} else {

search.Activate();

36
}

private void button5_Click(object sender, EventArgs e)

this.Close();

Making Form4 page as default page


using System;
using System.Collections.Generic; using System.Linq;
using System.Threading.Tasks; using
System.Windows.Forms;

namespace windows_form

static class Program

/// <summary>

/// The main entry point for the application.

/// </summary> [STAThread]


static void Main()

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;

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_MENU_PROGRAM

public partial class Form1 : Form


{

public Form1()

InitializeComponent();

private void qUITToolStripMenuItem_Click(object sender, EventArgs e)

Close();

private void lISTRECORDSINGRIDVIEWToolStripMenuItem_Click(object sender,


40
EventArgs e)

VIEW nForm = new VIEW();

nForm.Show(); }

private void iNSERTRECORDToolStripMenuItem_Click(object sender, EventArgs e)

INSERT nForm = new INSERT();

nForm.Show(); }

private void mODIFYRECORDToolStripMenuItem_Click(object sender, EventArgs e)

UPDATE nForm = new UPDATE();

nForm.Show(); }

private void dELETERECORDToolStripMenuItem_Click(object sender, EventArgs e)

DELETE nForm = new DELETE();

nForm.Show(); }

private void Form1_Load(object sender, EventArgs e) {

41
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; using System.Data.SqlClient;

namespace LOGIN_MENU_PROGRAM

public partial class INSERT : Form


{

public INSERT()

InitializeComponent();

} private void button3_Click(object sender, EventArgs e) {

Close();

private void button2_Click(object sender, EventArgs e)

42
textBox1.Text = ""; textBox2.Text = "";
textBox3.Text = ""; }

private void button1_Click(object sender, EventArgs e)

SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist

Security Info=False;Initial Catalog=student;Data Source=DESKTOP-FD039HC\\SQLEXPRESS");


con.Open();

string q = "select * from login where userid='" + textBox1.Text + "'and


password='" + textBox2.Text + "'";

SqlCommand cmd = new SqlCommand(q, con); SqlDataReader sdr =


cmd.ExecuteReader();

if (sdr.Read() == true)

MessageBox.Show("Record Exist, Try again....");

else {

string q1 = "insert login values ('" + textBox1.Text + "','" +


textBox2.Text + "','" + textBox3.Text + "')";

SqlCommand command = new SqlCommand(q1, con);

sdr.Close();

command.ExecuteNonQuery();

MessageBox.Show("Record Inserted Successfully..");

con.Close();

43
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; using System.Data.SqlClient;
namespace LOGIN_MENU_PROGRAM

public partial class UPDATE : Form


{

public UPDATE()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist

Security Info=False;Initial Catalog=student;Data Source=DESKTOP-FD039HC\\SQLEXPRESS");


con.Open();

string st = "select count(*) from login where userid='" + textBox1.Text +


"' and password='" + textBox2.Text + "'";
44
SqlCommand cmd = new SqlCommand(st, con); int x =
Convert.ToInt32(cmd.ExecuteScalar());

string tb2 = textBox2.Text;

if (x == 0)

MessageBox.Show("Record doesn't exist!");

} else

string q = "select * from login where userid='" + textBox1.Text +


"'and password='" + textBox2.Text + "'";

SqlCommand cmd1 = new SqlCommand(q, con);

SqlDataReader sdr = cmd1.ExecuteReader();

if (sdr.Read() == true)

{ string x1;

x1 = sdr["name"].ToString(); textBox4.Text = x1;


sdr.Close();

string q1 = "update login set password='" + textBox4.Text + "'


where userid='" + textBox1.Text + "'"; SqlCommand cmd2 = new
SqlCommand(q1, con);

cmd2.ExecuteNonQuery();

MessageBox.Show("Record updated succesfully...with " +

textBox4.Text + "");

con.Close();

} }

private void button2_Click(object sender, EventArgs e)

textBox1.Text =""; textBox2.Text = "";


textBox3.Text = ""; textBox4.Text = ""; }

private void button3_Click(object sender, EventArgs e)

45
{

Close();

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; using
System.Data.SqlClient; namespace LOGIN_MENU_PROGRAM

public partial class DELETE : Form


{

public DELETE()

InitializeComponent();

private void button3_Click(object sender, EventArgs e)

46
{

Close();

private void button2_Click(object sender, EventArgs e)

textBox1.Text = ""; textBox2.Text = "";


textBox3.Text = ""; }

private void button1_Click(object sender, EventArgs e)

SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist

Security Info=False;Initial Catalog=student;Data Source=DESKTOP-FD039HC\\SQLEXPRESS");


con.Open();

string q = "select * from login where userid='" + textBox1.Text + "'and


password='" + textBox2.Text + "'";

SqlCommand cmd = new SqlCommand(q, con); SqlDataReader sdr =


cmd.ExecuteReader();

if (sdr.Read() == true)

{ string x;

x = sdr["name"].ToString(); textBox3.Text = x;

string q1 = "delete login where userid = '" + textBox1.Text + "' and


password='" + textBox2.Text + "'";

SqlCommand command = new SqlCommand(q1, con);

sdr.Close();

command.ExecuteNonQuery(); MessageBox.Show("Record Deleted


Successfully..");

} else

MessageBox.Show("Record does not exist, try again ...."); con.Close();

47
namespace LOGIN_MENU_PROGRAM

partial class VIEW


{

/// <summary> /// Required designer variable.

/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary> /// Clean up any resources being used.

/// </summary>
/// <param name="disposing">true if managed resources should be disposed;

otherwise, false.</param>

protected override void Dispose(bool disposing)


{

if (disposing && (components != null))

components.Dispose();

base.Dispose(disposing); } #region Windows Form Designer


generated code
48
/// <summary>
/// Required method for Designer support - do not modify /// the contents of this method
with the code editor.

/// </summary>
private void InitializeComponent()

this.components = new System.ComponentModel.Container(); this.dataGridView1 = new


System.Windows.Forms.DataGridView();

this.loginBindingSource = new

System.Windows.Forms.BindingSource(this.components);

this.studentDataSet = new LOGIN_MENU_PROGRAM.studentDataSet();

this.loginTableAdapter = new

LOGIN_MENU_PROGRAM.studentDataSetTableAdapters.loginTableAdapter(); this.studentDataSet1 = new


LOGIN_MENU_PROGRAM.studentDataSet1(); this.loginBindingSource1 = new

System.Windows.Forms.BindingSource(this.components); this.loginTableAdapter1 = new

LOGIN_MENU_PROGRAM.studentDataSet1TableAdapters.loginTableAdapter();

this.useridDataGridViewTextBoxColumn = new

System.Windows.Forms.DataGridViewTextBoxColumn();

this.password = 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.DataSource = this.loginBindingSource1; this.dataGridView1.Location = new


System.Drawing.Point(0, 0);

this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.RowTemplate.Height = 24;

this.dataGridView1.Size = new System.Drawing.Size(454, 401);

this.dataGridView1.TabIndex = 0;

//

// loginBindingSource

//

this.loginBindingSource.DataMember = "login";

this.loginBindingSource.DataSource = this.studentDataSet;

//

// studentDataSet

//

this.studentDataSet.DataSetName = "studentDataSet"; this.studentDataSet.SchemaSerializationMode =

System.Data.SchemaSerializationMode.IncludeSchema;

//

// loginTableAdapter

//

this.loginTableAdapter.ClearBeforeFill = true;

//

// studentDataSet1

//

this.studentDataSet1.DataSetName = "studentDataSet1"; this.studentDataSet1.SchemaSerializationMode =


50
System.Data.SchemaSerializationMode.IncludeSchema;

//

// 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

//

this.password.DataPropertyName = "password"; this.password.HeaderText =


"password"; this.password.Name = "password";

//

// nameDataGridViewTextBoxColumn

//

this.nameDataGridViewTextBoxColumn.DataPropertyName = "name";
this.nameDataGridViewTextBoxColumn.HeaderText = "name";

this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn";

//

// VIEW

51
//

this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode =


System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450);

this.Controls.Add(this.dataGridView1);

this.Name = "VIEW"; this.Text = "Form2";

this.Load += new System.EventHandler(this.Form2_Load);

(( 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

private System.Windows.Forms.DataGridView dataGridView1;

private studentDataSet studentDataSet;

private System.Windows.Forms.BindingSource loginBindingSource; private


studentDataSetTableAdapters.loginTableAdapter loginTableAdapter;

private studentDataSet1 studentDataSet1;

private System.Windows.Forms.BindingSource loginBindingSource1; private


studentDataSet1TableAdapters.loginTableAdapter loginTableAdapter1;

private System.Windows.Forms.DataGridViewTextBoxColumn useridDataGridViewTextBoxColumn;

private System.Windows.Forms.DataGridViewTextBoxColumn password; private


System.Windows.Forms.DataGridViewTextBoxColumn

nameDataGridViewTextBoxColumn;

52
53
// 12) Program to validate the given user credentials with default values

// ASP.NET PROGRAM TO CREATE LOGIN FORM and EXECUTE.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace WebApplication6

public partial class WebForm1 : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)

if ( TextBox1.Text.ToUpper() == "USER1" && TextBox2.Text == "123")

Response.Write("VALID ID AND PASSWORD");

else
54
Response.Write("INVALID ID AND PASSWORD");

protected void Button2_Click(object sender, EventArgs e)

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;

public partial class _Default : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e) 45

if (!IsPostBack)

//Bind xml data to datalist

BindDatalist();

56
}

private void BindDatalist()

XmlTextReader xmlreader = new XmlTextReader(Server.MapPath("Sample.xml"));

DataSet ds = new DataSet();

ds.ReadXml(xmlreader);

xmlreader.Close();

if (ds.Tables.Count != 0)

DataList1.DataSource = ds;

DataList1.DataBind();

else

DataList1.DataSource = null;

DataList1.DataBind();

protected void Button1_Click(object sender, EventArgs e)

XmlDocument xmldoc = new XmlDocument();

xmldoc.Load(Server.MapPath("Sample.xml"));

BindDatalist();

protected void Button2_Click(object sender, EventArgs e)

string sex;

if(RadioButton1.Checked==true)

sex = RadioButton1.Text;
57
}

else

sex = RadioButton2.Text;

XmlDocument xmldoc = new XmlDocument();

xmldoc.Load(Server.MapPath("Sample.xml"));

XmlElement parentelement = xmldoc.CreateElement("Details");

XmlElement name = xmldoc.CreateElement("Name");

name.InnerText = TextBox1.Text;

XmlElement Roll_No = xmldoc.CreateElement("Roll_No");

Roll_No.InnerText = TextBox2.Text;

XmlElement Course = xmldoc.CreateElement("Course");

Course.InnerText = DropDownList1.SelectedItem.Text;

XmlElement Gender = xmldoc.CreateElement("Gender");

Gender.InnerText = sex;

XmlElement Email = xmldoc.CreateElement("Email");

Email.InnerText = TextBox3.Text;

XmlElement Phone_no = xmldoc.CreateElement("Phone_no");

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)

First open your ASP.Net web application in Visual Studio.

Now in the top we have the option Build. Click on that and under Build you will find Publish Website.

Click on Publish Website. Now open the publish web pop-up.

For Publish method select File System.

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.

Now open IIS manager. (Type inetmgr in the Run command.)

Right-click on Default Application and Add Application.

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

b) Write the steps to connect the database to the grid view(step 5)

// Program to implement grid view property of a table extracting from ADO.NET using windows forms

Step 1 : Gridview selection into ASP.NET from toolbox.

Step 2: Adding data source for gridview using database.

64
Step 3: Selecting data table columns to display in gridview.

Step 4: Test Query to check data records selected for 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

Step 1: Menu creation in ASP.NET

Step 2: Navigation of web forms created to link to display when selected.

67
Step 3: Selected Insert record menu option

Step 4: Update menu option selected form display.

Step 5 : Selected Delete 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;

public partial class _Default : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)

69
}

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)

70

You might also like