0% found this document useful (0 votes)
11 views

C# Record (3)

The document outlines the Visual Programming Lab course for the IV Semester at Sri Ramakrishna Mission Vidyalaya, focusing on C#.Net and Asp.Net applications. It includes a bonafide certificate, an index of practical exercises, and detailed algorithms and code examples for various programming tasks such as palindrome checking, command line arguments, a simple calculator, string handling, and jagged arrays. Each section provides aims, algorithms, and code snippets demonstrating the implementation of the respective programs.
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)
11 views

C# Record (3)

The document outlines the Visual Programming Lab course for the IV Semester at Sri Ramakrishna Mission Vidyalaya, focusing on C#.Net and Asp.Net applications. It includes a bonafide certificate, an index of practical exercises, and detailed algorithms and code examples for various programming tasks such as palindrome checking, command line arguments, a simple calculator, string handling, and jagged arrays. Each section provides aims, algorithms, and code snippets demonstrating the implementation of the respective programs.
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/ 57

SRI RAMAKRISHNA MISSION VIDYALAYA

COLLEGE OF ARTS AND SCIENCE


[AUTONOMOUS]

Re-Accredited by NAAC with A Grade


Coimbatore – 641 020

May – 2022

DEPARTMENT OF COMPUTER APPLICATIONS

NAME :

REG. NO :

SEMESTER : IV

SUBJECT : Visual Programming Lab


(C#.Net&Asp.Net)

SUBJECT CODE : 20UCA4CP05


SRI RAMAKRISHNA MISSION VIDYALAYA
COLLEGE OF ARTS AND SCIENCE
[AUTONOMOUS]
Re-Accredited by NAAC with A Grade
Coimbatore – 641 020

DEPARTMENT OF COMPUTER APPLICATIONS


BONAFIDE CERTIFICATE
This is certify that it is a bonafide record work done by
___________________________________ in "Visual Programming
Lab(C#.Net&Asp.Net)" for the IV Semester during the academic year 2021-
2022.Submitted for the Semester Practical Examinations held on _________________ .

Staff in Charge Head of the Department

Internal Examiner External Examiner


INDEX

PAGE
S.NO DATE PARTICULARS SIGN
NO
1 28-02-2022 Palindrome
2 03-03-2022 Command Line Arguments
3 07-03-2022 Simple Calculator

4 10-03-2022 String Handling Function

5 14-03-2022 Second Largest Number

6 17-03-2022 Jagged Array


Simple calculator
7 21-03-2022 (windows form application)
Web browser
8 24-03-2022 (windows form application)
Notepad application
9 28-03-2022
(windows form application)
Wordpad application
10 31-03-2022
(windows form application)
Database connectivity (windows
11 04-04-2022 form application)

12 07-04-2022 Asp.Net Application


1.PALINDROME

Aim:
To perform the palindrome program using c sharp.net application.

Algorithm:
Step1: Open the new text document.

Step2: Type the program in new notepad file .

Step3: Create a class name as “pallin”

Step4: In the main function denote data type int

Step5: This program contains the formula to the reverse (rev) function as

D=n%10

Rev=rev*10+d

N=n/10

Step6: Save the program with the extension of .cs

Step7: Open the visual studio comment prompt to run the program.

Step8: Compile the program by using the command as program name.cs

Step9: Run the program by giving the program name

Step10: Stop the program.

o Get the number from user


o Hold the number in temporary variable
o Reverse the number
o Compare the temporary number with reversed number
o If both numbers are same, print palindrome number
o Else print not palindrome number

1.PALINDROME

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;

namespace palindrome
{
internalclassProgram
{
staticvoid Main(string[] args)
{
int n, r, rev = 0, m;
Console.Write("Enter the number : ");
n = int.Parse(Console.ReadLine());
m = n;
while(n>0)
{
r = n % 10;
rev = (rev * 10) + r;
n = n / 10;
}
if (rev == m)
Console.WriteLine("The given number is Palindrom.");
else
Console.WriteLine("The given number is not Palindrom.");
Console.ReadLine();
}
}
}

Output:
Result:
The expected output verified and executed successfully.
using System;
namespace palindrome
{
class Program
{
static void Main(string[] args)
{
string s,revs="";
Console.WriteLine(" Enter string");
s = Console.ReadLine();
for (int i = s.Length-1; i >=0; i--) //String Reverse
{
revs += s[i].ToString();
}
if (revs == s) // Checking whether string is palindrome or not
{
Console.WriteLine("String is Palindrome \n Entered String Was {0}
and reverse string is {1}", s, revs);
}
else
{
Console.WriteLine("String is not Palindrome \n Entered String Was
{0} and reverse string is {1}", s, revs);
}
Console.ReadKey();
}
}
}
2.COMMANDLINE ARGUMENT

Aim:

To perform the command line argument program using c sharp.net application.

Algorithm:

Step1: Start the program.

Step2: Open the new text document.

Step3: Type the program and create a class name as program name.

Step4: Assign the arguments as a parameters inside and outside of the program.
Step5: Save the program with the extensions of .cs

Step6: Compile the program.

Step7: Run the program.


2. COMMAND LINE ARGUMENT

A) Argument with String

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespaceArgumentWithString
{
classProgram
{
staticvoid Main(string[] args)
{
Console.Write("welcome");
Console.Write(" " + args[0]);
}
}
}
Output:
B) Argument with Number

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;

namespaceArgumentWithNumbers
{
internalclassProgram
{
staticvoid Main(string[] args)
{
double a, b;
if(args.Length == 0)
{
Console.WriteLine("No arguments found!.");

}
else
{
a= double.Parse(args[0]);
b= double.Parse(args[1]);
double sum = 0, div = 0, mul = 0, sub = 0;
sum = a + b;
Console.WriteLine("the sum of {0} and {1} is : {2}", a, b, sum);
div = a / b;
Console.WriteLine("the divsion of {0} and {1} is : {2}", a, b, div);
mul = a * b;
Console.WriteLine("the multiplication of {0} and {1} is : {2}", a, b, mul);
sub = a - b;
Console.WriteLine("the subtraton of {0} and {1} is : {2}", a, b, sub);
Console.ReadLine();
}
}
}
}
Output:

Result:
The expected output verified and executed successfully.
3. SIMPLE CALCULATOR

Aim:
To perform the simple calculator using c sharp.net application.

Algorithms:
Step1: Create a new folder in a “d” drive and open the new text document in the folder.

Step2:Type the program in the new notepad file and save the file “simcalc”

Step3: Use the switch case to determine various operations in the program.

Step4: The operators are mainly used to perform the operations, Addition,subtraction,
multiplication and division.

Step5: Save the program with the extension of .cs

Step6: Open the visual studio comment prompt to compile and run the program.

Step7: Compile the program & given the program name .cs

Step8: Run the program by giving the program name and stop the program.
3. SIMPLE CALCULATOR

using System;

class simcalc

public static void Main(string[] args)

double a,b,rpt=1;

int choice;

while(rpt!=0)

Console.WriteLine("select the operations:");

Console.WriteLine("1.addition");

Console.WriteLine("2.subtraction");

Console.WriteLine("3.multiplication");

Console.WriteLine("4.division");

Console.WriteLine("5.exit");

Console.WriteLine("Enter your choice:");

choice=int.Parse(Console.ReadLine());

switch(choice)

case 1:

Console.WriteLine("Enter two number:");


a=double.Parse(Console.ReadLine());

b=double.Parse(Console.ReadLine());

Console.WriteLine("Result of addition:"+(a+b));

break;

case 2:

Console.WriteLine("Enter two number:");

a=double.Parse(Console.ReadLine());

b=double.Parse(Console.ReadLine());

Console.WriteLine("Result of subtraction:"+(a-b));

break;

case 3:

Console.WriteLine("Enter two number:");

a=double.Parse(Console.ReadLine());

b=double.Parse(Console.ReadLine());

Console.WriteLine("Result of multiplication:"+(a*b));

break;

case 4:

Console.WriteLine("Enter two number:");

a=double.Parse(Console.ReadLine());

b=double.Parse(Console.ReadLine());

if(b==0)

Console.WriteLine("division not possible");

}
else

Console.WriteLine("resultof division:"+(a/b));

break;

case 5:

rpt=0;

break;

default:

Console.WriteLine("invalid selection");

break;

}
Output:

Result:
The expected output verified and executed successfully.
4. STRING FUNCTION

Aim:
To perform the using string handling function program using c sharp.net application.

Algorithms:
Step1:Start the program.

Step2:Open the new text document

Step3: type the program in the text document

Step4: create the class which the name as strops.

Step5: Initialize the string variables as str1 str2 str3

Step6:using the strop and strlow functions to displays the string in capital letters and small letters.

Step7: using the some handlings functions like string length, string concatenation, string lower case,
string trim, string reverse and string comparisons are used in this program.

Step8: compile and run the program.


4. STRING FUNCTION

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace strops

class Program

static void Main(string[] args)

string str1 = "Ramakrishna Mission Vidyalaya";

string str2 = "Ramakrishna Mission Vidyalaya";

string str3 = "Vivekananda University";

string strUp, strLow;

int result, idx;

Console.WriteLine("str1:" + str1);

Console.WriteLine("Length of str1:" + str1.Length);

Console.WriteLine("str2:" + str2);

Console.WriteLine("Length of str2:" + str2.Length);

Console.WriteLine("str3:" + str3);

Console.WriteLine("Length of str3:" + str3.Length);

strLow = str1.ToLower(System.Globalization.CultureInfo.CurrentCulture);
strUp = str1.ToUpper(System.Globalization.CultureInfo.CurrentCulture);

Console.WriteLine("Lowercase version of str1:\n" + strLow);

Console.WriteLine("Uppercase version of str1:\n" + strUp);

Console.WriteLine("org str:" + str1);

string split = string.Empty;

string[] strarr = str1.Split(' ');

Console.WriteLine("split a string:");

for (int i = strarr.Length - 1; i >= 0; i--)

Console.WriteLine(strarr[i]);

string substr = str1.Substring(11, 16);

Console.WriteLine("substr:" + substr);

string input = str1;

char[] inputarray = input.ToCharArray();

Array.Reverse(inputarray);

string output = new string(inputarray);

Console.WriteLine("strrev:" + output);

Console.WriteLine();

Console.WriteLine("Display str1.one char at a time");

for (int i = 0; i < str1.Length; i++)

Console.WriteLine(str1[i]);

if (str1 == str2)

Console.WriteLine("str1==str2");

else
Console.WriteLine("str1=str2");

if (str1 == str3)

Console.WriteLine("str1==str3");

else

Console.WriteLine("str1==str3");

result = string.Compare(str1, str3, StringComparison.CurrentCulture);

if (result == 0)

Console.WriteLine("str1 and str3 are equal");

else if (result < 0)

Console.WriteLine("str1 is less than str3");

else

Console.WriteLine("str1 is greater than str3");

Console.WriteLine();

Console.WriteLine("One Two Three One");

Console.WriteLine();

str2 = "One Two Three One";

idx = str2.IndexOf("One", StringComparison.Ordinal);

Console.WriteLine("Index of first occurrence of one: " + idx);

idx = str2.LastIndexOf("one", StringComparison.Ordinal);

Console.WriteLine("Index of last Occurance of one:" + idx);

Console.ReadKey();

}
Output:
Result:
The expected output verified and executed successfully.
5. SECOND LARGEST NUMBER

Aim:
To find the second largest number using c sharp.net application.

Algorithms:
Step1: Start the program.

Step2: Open the new text document and type the program in the text document.

Step3: Create the class named as a program name.

Step4: Initialize the variable a, i, high, sechigh, temp in the main function

Step5: Using the int parse keyword use can get the integer.

Step6: Using the for loop condition to determine the length of the array.

Step7: Using the if-else statement to pick the second highest number in the given array.

Step8: Save the program with the extension of “.cs”

Step9: Compile and run the program.


5.SECOND LARGEST NUMBER

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;

namespaceSecondLargestnum
{
internalclassProgram
{
staticvoid Main(string[] args)
{
int a, i, high, sechigh, temp;
Console.WriteLine("Enter the array legth:");
a=int.Parse(Console.ReadLine());
int[] arr=newint[a];
Console.WriteLine("Enter the array element one by one:");
for(i=0;i<a;i++)
arr[i]=int.Parse(Console.ReadLine());
Console.WriteLine("Array elements are:");
for(i=0;i<arr.Length;i++)
Console.WriteLine(arr[i]+" ");
Console.WriteLine();
Console.WriteLine();
high = sechigh = arr[0];
for(i=0;i<arr.Length;i++)
{
temp = arr[i];
if(temp>high)
{
sechigh = high;
high= temp;
}
elseif(temp>sechigh&&temp!=high)
{
sechigh = temp;
}
}
Console.WriteLine("The Second largest number is: " + sechigh);
Console.ReadLine();

}
}

Output:

Result:
The expected output verified and executed successfully.
6. JAGGED ARRAY

Aim:
To perform the jagged array program using c sharp.net application.

Algorithms:
Step1: Start the program

Step2: Open the new text document and type the program in the text document.

Step3: Create the class named “myjaggedArr”

Step4: Initialize the variable i, j, in the main function

Step5: Using the for loop condition, Initialize the i variable and assign the zero value and made
increment process until the condition (i<3) has reached false

Step6:Using the for loop condition the position will be placed as like a matrix

Step7: Save and compile the program.

Step8:Run the program.


6. JAGGED ARRAY

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace program_myjagger

class Program

static void Main(string[] args)

int[][] myjag = new int[3][];

for(int i=0;i<myjag.Length;i++)

myjag[i]=new int[i+3];

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

Console.WriteLine("Enter the elements of row{0}:",i);

for(int j=0;j<myjag[i].Length;j++)

myjag[i][j]=int.Parse(Console.ReadLine());

}
int sum=0;

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

for(int j=0;j<myjag[i].Length;j++)

sum+=myjag[i][j];

Console.WriteLine("sum="+sum);

Console.Read();

}
Output:

Result:
The expected output verified and executed successfully.
7. SIMPLE CALCULATOR (WINDOWS FORM APPLICATION)

Aim:
To perform the c# windows application with simple calculator operations.

Algorithm:
Step 1: Open the visual studio 2010 and select the file menunewprojectwindows c#
 windows form applications.

Step2: Design the form as per the calculator display.Using the tools windows.Select the
button,textboxand label to click and drag the button in the approximate position.

Step3:Type the code for approximate buttons before that change the caption of the buttons before that
change the caption of the button as per the calculator design so in every button we need to type as per
approximate code

Eg:button 1

Text box1.text=Text box1.text+1;

Step 4:Type the code for operation buttons.

Eg:button +

Intans=Textbox1.text+int.Parse(Textbox1.text);

Textbox1.text=ans;

Intans,num;

Ans=num+float.Parse(Textbox.text);

Textbox1.text=ans.ToString();

Step5:Create a clear button for clearing the textbox.

Textbox1.text=” “;

Step 6:Execute the the file to the start button.


7. SIMPLE CALCULATOR (WINDOWS FORM APPLICATION)

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace calculator

public partial class Form1 : Form

float num, ans,sq;

int count;

public Form1()

InitializeComponent();

private void Form1_Load(object sender, EventArgs e)

private void button6_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 5;
textBox1.ForeColor = Color.Black;

private void button9_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 1;

textBox1.ForeColor = Color.Black;

private void button11_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 3;

textBox1.ForeColor = Color.Black;

private void button3_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 9;

textBox1.ForeColor = Color.Black;

private void button10_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 2;

textBox1.ForeColor = Color.Black;

private void button5_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 4;
textBox1.ForeColor = Color.Black;

private void button7_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 6;

textBox1.ForeColor = Color.Black;

private void button1_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 7;

textBox1.ForeColor = Color.Black;

private void button2_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 8;

textBox1.ForeColor = Color.Black;

private void button14_Click(object sender, EventArgs e)

textBox1.Text = textBox1.Text + 0;

textBox1.ForeColor = Color.Black;

private void button13_Click(object sender, EventArgs e)

{
textBox1.Text = textBox1.Text + ".";

private void button15_Click(object sender, EventArgs e)

compute();

label1.Text = " "

private void button16_Click(object sender, EventArgs e)

num = float.Parse(textBox1.Text);

textBox1.Clear();

textBox1.Focus();

count = 2;

label1.Text = num.ToString() + "+";

private void button12_Click(object sender, EventArgs e)

num = float.Parse(textBox1.Text);

textBox1.Clear();

textBox1.Focus();

count = 1;

label1.Text = num.ToString() + "-";

private void button8_Click(object sender, EventArgs e)

{
num = float.Parse(textBox1.Text);

textBox1.Clear();

textBox1.Focus();

count = 3;

label1.Text = num.ToString() + "*";

private void button4_Click(object sender, EventArgs e)

num = float.Parse(textBox1.Text);

textBox1.Clear();

textBox1.Focus();

count = 3;

label1.Text = num.ToString() + "*";

public void compute()

switch (count)

case 1:

ans = num - float.Parse(textBox1.Text);

textBox1.Text = ans.ToString();

break;

case 2:

ans = num + float.Parse(textBox1.Text);

textBox1.Text = ans.ToString();
break;

case 3:

ans = num * float.Parse(textBox1.Text);

textBox1.Text = ans.ToString();

break;

case 4:

ans = num / float.Parse(textBox1.Text);

textBox1.Text = ans.ToString();

break;

case 5:

ans = num * float.Parse(textBox1.Text);

textBox1.Text = ans.ToString();

break;

private void button18_Click(object sender, EventArgs e)

textBox1.Clear();

private void button17_Click(object sender, EventArgs e)

MessageBox.Show("claculator closed");

this.Close();

}}

}
OUTPUT:

Result:
The expected output verified and executed successfully.
8.WEB BROWSER

Aim:
To perform the c# Web browser application in c# windows form.

Algorithm:
Step 1:open the visual studio 2010 and select the file menunewprojectwindows c# windows
form applicationsfile nameok.

Step2:Design the form as per the Web browser application.

Step3:Add tool strip menu,menustrip and web browser tool in the first form.

Step 4: Type a code for go button.

webBrowser1.Navigate(toolStripTextBox1.Text);

Step5:Type a code for refresh button.

webBrowser1.Refresh();

Step 6: Type a code for back and forward button.

webBrowser1.Goback();

webBrowser1.GoForward();

Step 7: Type a code for print.

webBrowser1.print();

Step 8:Type a code for Exit and stop.

Application.Exit();

webBrowser1.stop();

Step 9:Compile and run the program without error.


8.WEB BROWSER

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace web_browser1

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void button7_Click(object sender, EventArgs e)

Application.Exit();

private void button1_Click(object sender, EventArgs e)

webBrowser1.Refresh();
}

private void button2_Click(object sender, EventArgs e)

webBrowser1.Stop();

private void button3_Click(object sender, EventArgs e)

webBrowser1.GoBack();

private void button4_Click(object sender, EventArgs e)

webBrowser1.GoForward();

private void button5_Click(object sender, EventArgs e)

webBrowser1.Print();

private void button6_Click(object sender, EventArgs e)

webBrowser1.Navigate(textBox1.Text);

}
Output:

Result:
The expected output verified and executed successfully.
9. NOTEPAD APPLICATION

Aim:
To perform the c# Notepad application with sum menu operations.

Algorithm:
Step 1: Open the visual studio 2010 and select the file menunewprojectwindows c# windows
form applicationsfile nameok.

Step2: Design the form as per the Notepad application.

Step3: Type the code for approximate menu button

Step 4: Add the menu Strip into the form

Step5: Type a code for new menu button.

String path;

Path=string.Empty();

Textbox.clear();

Step 6: Type a code for new open menu.

using (OpenFileDialog.ofd = new OPenFileDialog()

{ Filter = "TextDocuments|*.txt", ValidateNames = true,multiselect=false })

Step 7: Type a code for new open menu.

using (SaveFileDialogsfd = new SaveFileDialog()

{ Filter = "TextDocuments|*.txt", ValidateNames = true })

Step 8:Type a code for exit menu.

Application.Exit();

Step 9: Compile and run the program without error.


9.NOTEPAD APPLICATION

using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
using System.IO;
usingSystem.Windows.Forms;

namespacenoteBad
{
publicpartialclassForm1 : Form
{
string path;
publicForm1()
{
InitializeComponent();
}

privatevoidnewToolStripMenuItem_Click(object sender, EventArgs e)


{
path = String.Empty;
richTextBox1.Clear();
}

privatevoidsaveToolStripMenuItem_Click(object sender, EventArgs e)


{
if(string.IsNullOrEmpty(path))
{
using (SaveFileDialogsfd = newSaveFileDialog() { Filter = "TextDocuments|*.txt", ValidateNames = true })
{
if(sfd.ShowDialog() == DialogResult.OK)
{
using(StreamWritersw=newStreamWriter(sfd.FileName))
{
sw.WriteLine(richTextBox1.Text);
}
}
}
}
}

privatevoidopenToolStripMenuItem_Click(object sender, EventArgs e)


{
OpenFileDialog OpenFileDialog1 = newOpenFileDialog();
OpenFileDialog1.ShowDialog();
StreamReadersr = newStreamReader(OpenFileDialog1.FileName);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();

privatevoidexitToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}

}
}
Output:

Result:
The expected output verified and executed successfully.
10. Wordpad application

Aim:
To perform the c# Wordpad application in c# windows form.

Algorithm:
Step 1:open the visual studio 2010 and select the file menunewprojectwindows c# windows
form applicationsfile nameok.

Step2:Design the form as per the Wordpad application.

Step3: Type a code for new menu button.

richTextBox1.Clear();

Step 4: Type a code for open menu button.

openFileDialog1.ShowDialog();
System.IO.StreamReaderofd = new System.IO.StreamReader(openFileDialog1.FileName);
richTextBox1.Text = ofd.ReadToEnd();
ofd.Close();

Step5:Type a code for save menu button.

if (string.IsNullOrEmpty(Path))
using (SaveFileDialogsfd = new SaveFileDialog() { Filter = "TextDocument|*.txt", ValidateNames =
true })
if (sfd.ShowDialog() == DialogResult.OK)
using (System.IO.StreamWritersw = new System.IO.StreamWriter(sfd.FileName))
sw.WriteLine(richTextBox1.Text);

Step 6:Type a code for Exit button

Application.Exit();

Step 7:Compile and run the program without error.

10.WORDPAD APPLICATION
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
using System.IO;
usingSystem.Windows.Forms;

namespacewordbad
{
publicpartialclassForm1 : Form
{
string path;
publicForm1()
{
InitializeComponent();
}

privatevoidcopyToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Copy();
}
privatevoidpasteToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Paste();
}
privatevoidcutToolStripMenuItem_Click(object sender, EventArgs e)
{

richTextBox1.Cut();
}
privatevoidselectAllToolStripMenuItem_Click(object sender, EventArgs e)
{

richTextBox1.SelectAll();
}

PrivatevoidnewToolStripMenuItem_Click(object sender, EventArgs e)


{
path = String.Empty;
richTextBox1.Clear();
}

privatevoidsaveToolStripMenuItem_Click(object sender, EventArgs e)


{
if(string.IsNullOrEmpty(path))
{
using (SaveFileDialogsfd = newSaveFileDialog() { Filter = "TextDocuments|*.txt", ValidateNames =
true })
{
if(sfd.ShowDialog() == DialogResult.OK)
{
using(StreamWritersw=newStreamWriter(sfd.FileName))
{
sw.WriteLine(richTextBox1.Text);
}
}
}
}
}

privatevoidopenToolStripMenuItem_Click(object sender, EventArgs e)


{
OpenFileDialog OpenFileDialog1 = newOpenFileDialog();
OpenFileDialog1.ShowDialog();
StreamReadersr = newStreamReader(OpenFileDialog1.FileName);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();

privatevoidexitToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}

}
}
Output:

Result:
The expected output verified and executed successfully.
11.DATABASE CONNECTIVITY

Aim:

To perform the database connectivity in c# windows forms application.

Algorithm:
Step 1:open the visual studio 2010 and select the file menunewprojectwindows c# windows
form applicationsfile nameok.

Step 2:Design the form as per the columns in the database.

Step 3: Add (using System.Data.SqlClient;) in the program.

Step 4: Use SqlConnection, SqlDataAdapter , SqlCommand , DataSet to connect a database.

Step 5 :Create a object for sqlcommand and get the values from the user.

Step 6 :Type a code for save button.

cmd = new SqlCommand("insert into tbl_studatabaseconnectivitytest values('" +


txtregno.Text + "','" + txtsname.Text + "','" + txtprogramme.Text + "','" + txtsyear.Text
+ "','" + txtsem.Text + "')", con);
cmd.ExecuteNonQuery();

Step 7:Compile and run the program without error.


11.DATABASE CONNECTIVITY

using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Data.SqlClient;
usingSystem.Windows.Forms;

namespace WindowsFormsApp1
{
publicpartialclassForm1 : Form
{
SqlConnection conn=newSqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Dell\Documents\crtdatab.mdf;Integrated
Security=True;Connect Timeout=30");
SqlCommandcmd;
SqlDataAdapter adapter;
DataSet ds=newDataSet();

publicForm1()
{
InitializeComponent();
}

privatevoid Form1_Load(object sender, EventArgs e)


{
conn.Open();
ds.Clear();
adapter = newSqlDataAdapter("Select * from Table2",conn);
adapter.Fill(ds);
}

privatevoid button1_Click(object sender, EventArgs e)


{
cmd = newSqlCommand("insert into Table2 values('" + textBox1.Text + "','" + textBox2.Text + "','" +
textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "')",conn);
cmd.ExecuteNonQuery();
MessageBox.Show("inserted succesfully");
}
}
}

Output:

Result:
The expected output verified and executed successfully.
12.ASP.NET APPLICATION

Aim:
To perform the Asp.net application in c# windows form.

Algorithm:
Step 1:Open the visual studio 2010 and select the file menunew websitewindows c# Asp.Net
empty filefile nameok.

Step2:Design the form as per the Asp.Net application to connect database.

Step3:Add (using System.Data.OleDb;) in the program.

Step 4: Use OleDbConnection con, OleDbCommandcmd, to connect a database.

Step 5 :Create a object for OleDbConnection , OleDbCommandand get the values from the
user.

Step 6 :Type a code for save button.

stringqry = "insert into tbl_student values ('" + txtregno.Text.ToString() + "','" +


txtsname.Text.ToString() + "')";
cmd = new OleDbCommand(qry, con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();

Step 7: Compile and run the program without error.


12. ASP.NET APPLICATION

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingSystem.Data.OleDb;
usingSystem.Configuration;

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


{
OleDbConnection con;
OleDbCommandcmd;

protected void Page_Load(object sender, EventArgs e)


{
con = new OleDbConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString;
if (con.State == ConnectionState.Closed)
con.Open();
}
protected void BtnSave_Click(object sender, EventArgs e)
{
stringqry = "insert into tbl_student values ('" + txtregno.Text.ToString() + "','" +
txtsname.Text.ToString() + "')";

cmd = new OleDbCommand(qry, con);


cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
Response.Write("Saved Successfully");
}
}
Output:

Result:
The expected output verified and executed successfully.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy