PROGRAMMING FOR APPLICATION DEVELOPMENT Lab Manual 2021-22
PROGRAMMING FOR APPLICATION DEVELOPMENT Lab Manual 2021-22
LABORATORY MANUAL
B.TECH
(IV YEAR – I SEM)
(2021-22)
VISION
To achieve high quality in technical education that provides the skills and attitude to adapt
to the global needs of the Information Technology sector, through academic and research
excellence.
MISSION
To equip the students with the cognizance for problem solving and to improve the teaching
learning pedagogy by using innovative techniques.
To strengthen the knowledge base of the faculty and students with motivation towards
possession of effective academic skills and relevant research experience.
To promote the necessary moral and ethical values among the engineers, for the betterment
of the society.
To create and sustain a community of learning in which students acquire knowledge and
learn to apply it professionally with due consideration for ethical, ecological and economic
issues.
To provide knowledge based services to satisfy the needs of society and the industry by
providing hands on experience in various technologies in core field.
To make the students to design, experiment, analyze, interpret in the core field with the
help of other multi disciplinary concepts wherever applicable.
To educate the students to disseminate research findings with good soft skills and become a
successful entrepreneur
1. Fundamentals and critical knowledge of the Computer System:- Able to Understand the
working principles of the computer System and its components , Apply the knowledge to
build, asses, and analyze the software and hardware aspects of it .
3. Applications of Computing Domain & Research: Able to use the professional, managerial,
interdisciplinary skill set, and domain specific tools in development processes, identify the
research gaps, and provide innovative solutions to them.
1. Students are advised to come to the laboratory at least 5 minutes before (to the starting time),
those who come after 5 minutes will not be allowed into the lab.
2. Plan your task properly much before to the commencement, come prepared to the lab with the
synopsis / program / experiment details.
3. Student should enter into the laboratory with:
a. Laboratory observation notes with all the details (Problem statement, Aim, Algorithm,
Procedure, Program, Expected Output, etc.,) filled in for the lab session.
b. Laboratory Record updated up to the last session experiments and other utensils (if any) needed
in the lab.
c. Proper Dress code and Identity card.
4. Sign in the laboratory login register, write the TIME-IN, and occupy the computer system
allotted to you by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab observation note
book, and get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff, must maintain the
discipline and decency in the laboratory.
7. Computer labs are established with sophisticated and high end branded systems, which should
be utilized properly.
8. Students / Faculty must keep their mobile phones in SWITCHED OFF mode during the lab
sessions. Misuse of the equipment, misbehaviors with the staff and systems etc., will attract
severe punishment.
9. Students must take the permission of the faculty in case of any urgency to go out; if anybody
found loitering outside the lab / class without permission during working hours will be treated
seriously and punished appropriately.
10. Students should LOG OFF/ SHUT DOWN the computer system before he/she leaves the lab
after completing the task (experiment) in all aspects. He/she must ensure the system / seat is
kept properly.
WEEK-1: DATE:
a) Learning to use Visual Studio 2019 IDE Building Console Application Project
1. Check the system requirements. These requirements help you know whether your
computer supports Visual Studio 2019.
2. Apply the latest Windows updates. These updates ensure that your computer has both
the latest security updates and the required system components for Visual Studio.
3. Reboot. The reboot ensures that any pending installs or updates don't hinder the Visual
Studio install.
4. Free up space. Remove unneeded files and applications from your %SystemDrive% by,
for example, running the Disk Cleanup app.
To do so, choose the following button, choose the edition of Visual Studio that you want,
choose Save, and then choose Open folder.
1. From your Downloads folder, double-click the bootstrapper that matches or is similar
to one of the following files:
o vs_community.exe for Visual Studio Community
o vs_professional.exe for Visual Studio Professional
o vs_enterprise.exe for Visual Studio Enterprise
2. We'll ask you to acknowledge the Microsoft License Terms and the Microsoft Privacy
Statement. Choose Continue.
For example, choose the "ASP.NET and web development" workload. It comes with
the default core editor, which includes basic code editing support for over 20
languages, the ability to open and edit code from any folder without requiring a project,
and integrated source code control.
Next, status screens appear that show the progress of your Visual Studio installation.
Tip
At any time after installation, you can install workloads or components that you didn't install
initially. If you have Visual Studio open, go to Tools > Get Tools and Features... which
opens the Visual Studio Installer. Or, open Visual Studio Installer from the Start menu.
From there, you can choose the workloads or components that you wish to install. Then,
choose Modify.
You can reduce the installation footprint of Visual Studio on your system drive. You can
choose to move the download cache, shared components, SDKs, and tools to different drives,
and keep Visual Studio on the drive that runs it the fastest.
Important
You can select a different drive only when you first install Visual Studio. If you've already
installed it and want to change drives, you must uninstall Visual Studio and then reinstall it.
You can also filter your search for a specific programming language by using
the Language drop-down list. You can filter by using the Platform list and the Project
type list, too.
4. Visual Studio opens your new project, and you're ready to code!
The Visual Studio integrated development environment is a creative launching pad that you
can use to edit, debug, and build code, and then publish an app. An integrated development
environment (IDE) is a feature-rich program that can be used for many aspects of software
development. Over and above the standard editor and debugger that most IDEs provide,
Visual Studio includes compilers, code completion tools, graphical designers, and many more
features to ease the software development process.
Create a project
First, you'll create a C# application project. The project type comes with all the template files
you'll need, before you've even added anything!
3. On the Create a new project window, enter or type console in the search box. Next,
choose C# from the Language list, and then choose Windows from the Platform list.
After you apply the language and platform filters, choose the Console App (.NET
Core) template, and then choose Next.
4. In the Configure your new project window, type or enter HelloWorld in the Project
name box. Then, choose Create.
(To do so, it calls the WriteLine method to display the literal string "Hello World!" in the
console window.)
If you press F5, you can run the program in Debug mode. However, the console window is
visible only for a moment before it closes.
(This behavior happens because the Main method terminates after its single statement
executes, and so the application ends.)
1. Add the following code immediately after the call to the WriteLine method:
C#Copy
Console.ReadLine();
WEEK-2: DATE:
a) Write a Program to generate the factorial of a given number by using command line
argument
using System;
namespace labprograms
{
class factorial
{
static void Main (String [] args)
{
int n = Convert.ToInt32(args[0]);
int n1 = n;
int fact=1;
for(int i=n;n>0;n--)
{
fact = fact * n;
}
Console.WriteLine("the factorial of " + n1 + ":" + fact);
Console.ReadLine();
}
}
using System;
namespace labprogarms
{
class fib
{
static void Main()
{
int n1 = 0, n2 = 1, n3, i;
Console.WriteLine("enter the number");
int n = Convert.ToInt32(Console.ReadLine());
Console.Write(n1 + " " + n2 + " "); //printing 0 and 1
for (i = 2; i < n; ++i) //loop starts from 2 because 0 and 1 are already printed
{
n3 = n1 + n2;
Console.Write(n3 + " ");
n1 = n2;
n2 = n3;
}
}
}
}
Three test outputs:
using System;
using System.Collections.Generic;
using System.Text;
namespace labprograms
{
class Temp
{
static void Main()
{
int celsius, faren;
Console.WriteLine("Enter the Temperature in Celsius(°C) : ");
celsius = int.Parse(Console.ReadLine());
faren = (celsius * 9) / 5 + 32;
Console.WriteLine("0Temperature in Fahrenheit is(°F) : " + faren);
Console.ReadLine();
}
}
}
Three test outputs:
WEEK-3: DATE:
using System;
using System.Collections.Generic;
using System.Text;
namespace PAD_lab_programs
{
class week3a
{
static void Main(string[] args)
{
System.Console.WriteLine("Pascal Triangle Program");
System.Console.Write("Enter the number of rows: ");
string input = System.Console.ReadLine();
int n = Convert.ToInt32(input);
for (int y = 0; y < n; y++)
{
int c = 1;
for (int q = 0; q < n - y; q++)
{
System.Console.Write(" ");
}
for (int x = 0; x <= y; x++)
{
System.Console.Write(" {0} ", c);
c = c * (y - x) / (x + 1);
}
System.Console.WriteLine();
System.Console.WriteLine();
}
System.Console.WriteLine();
}
}
}
b) Write a program which asks for a symbol and a width, and displays a triangle of that
width, using that number for the inner symbol
using System;
using System.Collections.Generic;
using System.Text;
namespace PAD_lab_programs
{
class Week3b
{
public static void Main()
{
Console.Write("Input a number: ");
int num = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the desired width: ");
int width = Convert.ToInt32(Console.ReadLine());
int height = width;
for (int row = 0; row < height; row++)
{
for (int column = 0; column < width; column++)
{
Console.Write(num);
}
Console.WriteLine();
width--;
}
}
}
}
WEEK-4: DATE:
using System;
using System.Collections.Generic;
using System.Text;
namespace PAD_lab_programs
{
class Week4a
{
public static void Main()
{
int n, i, j = 0, lrg, lrg2nd;
int[] arr1 = new int[50];
lrg = 0;
for (i = 0; i < n; i++)
{
if (lrg < arr1[i])
{
lrg = arr1[i];
j = i;
}
}
/* ignore the largest element and find the 2nd largest element in the array */
lrg2nd = 0;
for (i = 0; i < n; i++)
{
Department of Information Technology Page 23
PAD LAB 2021-2022
if (i == j)
{
i++; /* ignoring the largest element */
// i--;
}
else
{
if (lrg2nd < arr1[i])
{
lrg2nd = arr1[i];
}
}
}
Console.Write("The Second largest element in the array is : {0} \n\n", lrg2nd);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace PAD_lab_programs
{
class week4b
{
public static void Main()
{
int[] arr1 = new int[20];
int n, i,flag=0;
Console.WriteLine("enter the size of the array");
n=Convert.ToInt32(Console.ReadLine());
Console.Write("Input {0} elements in the array :\n", n);
for (i = 0; i < n; i++)
{
Console.Write("element - {0} : ", i);
arr1[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("enter the number to be searched");
int key = Convert.ToInt32(Console.ReadLine());
for (i=0;i<n;i++)
{
if(arr1[i]==key)
{
flag = 1;
break;
}
}
if (flag == 1)
Console.WriteLine("element is found at location" + (i+1));
else
Console.WriteLine("element not found");
}
}
}
Three test outputs:
WEEK-5: DATE:
using System;
using System.Collections.Generic;
using System.Text;
namespace lab_programs
{
classTTT
{
char[] square = { 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;
elseif (square[4] == square[5] && square[5] == square[6])
return 1;
elseif (square[7] == square[8] && square[8] == square[9])
return 1;
elseif (square[1] == square[4] && square[4] == square[7])
return 1;
elseif (square[2] == square[5] && square[5] == square[8])
return 1;
elseif (square[3] == square[6] && square[6] == square[9])
return 1;
elseif (square[1] == square[5] && square[5] == square[9])
return 1;
elseif (square[3] == square[5] && square[5] == square[7])
return 1;
elseif (square[1] != '1'&& square[2] != '2'&& square[3] != '3'&&
square[4] != '4'&& square[5] != '5'&& square[6] != '6'&& square[7]
!= '7'&& square[8] != '8'&& square[9] != '9')
return 0;
else
return -1;
}
void board()
{
Console.WriteLine("\n\n\tTic Tac Toe\n\n");
Console.WriteLine("Player 1 (X) - Player 2 (O)\n\n\n");
Console.WriteLine(" | | \n");
Console.WriteLine(" {0} | {1} | {2} \n", square[1], square[2], square[3]);
Console.WriteLine("_____|_____|_____\n");
Console.WriteLine(" | | \n");
Console.WriteLine(" {0} | {1} | {2} \n", square[4], square[5], square[6]);
Console.WriteLine("_____|_____|_____\n");
Console.WriteLine(" | | \n");
Console.WriteLine(" {0} | {1} | {2} \n", square[7], square[8], square[9]);
Console.WriteLine(" | | \n\n");
}
int player = 1,choice;
char mark;
staticvoid Main()
{
int i;
TTT t = new TTT();
do
{
t.board();
if (t.player % 2 == 1)
t.player = 1;
else
t.player = 2;
Console.WriteLine("Player {0}, enter a number ", t.player);
t.choice = Int32.Parse(Console.ReadLine());
if (t.player == 1)
t.mark = 'X';
else
t.mark = 'O';
if (t.choice == 1 && t.square[1] == '1')
t.square[1] = t.mark;
elseif (t.choice == 2 && t.square[2] == '2')
t.square[2] = t.mark;
elseif (t.choice == 3 && t.square[3] == '3')
t.square[3] = t.mark;
elseif (t.choice == 4 && t.square[4] == '4')
t.square[4] = t.mark;
elseif (t.choice == 5 && t.square[5] == '5')
t.square[5] = t.mark;
elseif (t.choice == 6 && t.square[6] == '6')
t.square[6] = t.mark;
elseif (t.choice == 7 && t.square[7] == '7')
t.square[7] = t.mark;
elseif (t.choice == 8 && t.square[8] == '8')
t.square[8] = t.mark;
elseif (t.choice == 9 && t.square[9] == '9')
t.square[9] = t.mark;
else
{
Console.WriteLine("Invalid move ");
t.player--;
}
i = t.checkwin();
t.player++;
} while (i == -1);
t. board();
if (i == 1)
Console.WriteLine("==> player {0} win", --t.player);
else
Console.WriteLine("==>\aGame draw");
}
}
Three test outputs:
using System;
using System.Collections.Generic;
using System.Text;
namespace lab_programs
{
class ChangChar
{
public static void ChangeChar(ref string text, int position, char letter)
{
text = text.Remove(position, 1);
text = text.Insert(position, letter.ToString());
}
public static void Main()
{
string sentence = "Tomato";
Console.WriteLine("The string is {0}", sentence);
ChangeChar(ref sentence, 5, 'a');
WEEK-6: DATE:
a) Create a base class, Telephone, and derive a class ElectronicPhone from it. In
Telephone, create a protected string member phonetype, and a public method Ring( )
that outputs a text message like this: "Ringing the ." In ElectronicPhone, the
constructor should set the phonetype to "Digital." In the Run( ) method, call Ring( )
on the ElectronicPhone to test the inheritance.
using System;
using System.Collections.Generic;
using System.Text;
namespace PAD_lab_programs
{
class telephone
{
protected string phonetype;
public void ring()
{
Console.WriteLine("ringing the {0} phone ...", phonetype);
}
}
class electronicphone : telephone
{
public electronicphone()
{
phonetype = "digital";
}
public void run()
{
ring();
}
}
class Test
{
static void Main()
{
electronicphone ep = new electronicphone();
ep.run();
Console.ReadKey();
}
}
}
Three test outputs:
b) Extend above Exercise to illustrate a polymorphic method. Have the derived class
override the Ring( ) method to display a different message
using System;
using System.Collections.Generic;
using System.Text;
namespace PAD_lab_programs
{
class telephone1
{
protected string phonetype;
public virtual void ring()
{
Console.WriteLine("ringing the {0} ...", phonetype);
}
}
class electronicphone1 : telephone1
{
public electronicphone1()
{
phonetype = "digital";
}
public void run()
{
ring();
}
public override void ring()
{
Console.WriteLine("the {0} phone is using a different ring-tone ...", phonetype);
}
}
class Test1
{
static void Main()
{
electronicphone1 ep = new electronicphone1();
ep.run();
Console.ReadKey();
}
}
}
Three test outputs:
WEEK-7: DATE:
a) Write a program to create interface named test. In this interface the member function
is square. Implement this interface in arithmetic class. Create one new class called To
Test Int in this class use the object of arithmetic class.
namespace PAD_lab_programs
{
public interface Test
{
public int square(int a);
}
class arithmetic implements Test
{
int s = 0;
public int square(int b)
{
Console.WriteLine (―Inside arithmetic class – implemented method square‖);
Console.WriteLine (―Square of ― + ― is ―+s);
return s;
}
void armeth()
{
Console.WriteLine (―Inside method of class Arithmetic‖);
}
}
class ToTestInt
{
public static void Main(String a[])
{
Console.WriteLine (―calling from ToTestInt class main method‖);
Test t = new arithmetic();
Console.WriteLine (―==============================‖);
Console.WriteLine (―created object of test interface – reference Arithmetic class ―);
Console.WriteLine (―Hence Arithmetic class method square called‖);
Console.WriteLine (―This object cannot call armeth method of Arithmetic class‖);
Console.WriteLine (―=================================‖);
t.square(10);
Console.WriteLine (―=================================‖);
}
}
}
Three test outputs:
b) Create an outer class with a function display, again create another class inside the
outer class named inner with a function called display and call the two functions in
the main class.
class Outer{
String so = (―This is Outer Class‖);
void display()
{
Console.WriteLine (so);
}
void test(){
Inner inner = new Inner();
inner.display();
}
//this is an inner class
class Inner{
String si =(―This is inner Class‖);
void display(){
Console.WriteLine (si);
}
}
}
class InnerClassDemo{
public static void Main(String args[]){
Outer outer = new Outer();
outer.display();
outer.test();
}
}
Three test outputs:
WEEK-8: DATE:
a) Write a program for example of try and catch block. In this check whether the given
array size is negative or not.
namespace PAD_lab_programs
{
classClass7a
{
public static void Main(String[] args)
{
int asize; ;
try
{
Console.WriteLine("enter array size-positive / negative");
asize = Convert.ToInt32(Console.ReadLine());
if (asize < 0)
thrownew ArgumentOutOfRangeException(" negative array size exception");
else
Console.WriteLine(" array sixe is positive number");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
b) Write a program to illustrate usage of try multiple catch with finally clause
using System;
using System.Collections.Generic;
using System.Text;
namespace PAD_lab_programs
{
class Class7b
{
static void Main()
{
int[] number = { 8, 17, 24, 5, 25 };
int[] divisor = { 2, 0, 0, 5 };
// --------- try block ---------
for (int j = 0; j < number.Length; j++)
// Here this block raises two different types of exception, i.e. divideByZeroException
// and IndexOutOfRangeException
try
{
Console.WriteLine("Number: " + number[j]);
Console.WriteLine("Divisor: " + divisor[j]);
Console.WriteLine("Quotient: " + number[j] / divisor[j]);
}
// Catch block 1 This Catch block is for handling DivideByZeroException
catch (DivideByZeroException)
{
Console.WriteLine("Not possible to Divide by zero");
}
// Catch block 2 This Catch block is for handling IndexOutOfRangeException
catch (IndexOutOfRangeException)
{
Console.WriteLine("Index is Out of Range");
}
finally
{
Console.WriteLine("finally block");
}
}
}
Three test outputs:
c) Write a program for creation of user defined exception to show whether candidate is
eligible to caste vote.
using System;
using System.Collections.Generic;
using System.Text;
namespace PAD_lab_programs
{
publicclassInvalidAgeException : Exception
{
publicInvalidAgeException(String message)
: base(message)
{
}
}
publicclassTestUserDefinedException
{
staticvoid validate(int age)
{
if (age < 18)
{
thrownew InvalidAgeException("Sorry, Age must be greater than 18");
}
}
publicstaticvoid Main(string[] args)
{
try
{
validate(12);
}
catch (InvalidAgeException e) { Console.WriteLine(e.Message); }
finally
{
Console.ReadLine();
}
}
}
}
Three test outputs:
WEEK-9: DATE:
a) Create a console application that displays current date a time for 10 times with the
time interval of 2 seconds use sleep() method
using System;
using System.Threading;
namespace PAD_lab_programs
{
class MyThread
{
public void Thread1()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
Thread.Sleep(200);
}
}
}
public class ThreadExample
{
public static void Main()
{
MyThread mt = new MyThread();
Thread t1 = new Thread(new ThreadStart(mt.Thread1));
Thread t2 = new Thread(new ThreadStart(mt.Thread1));
t1.Start();
t2.Start();
}
}
}
Three test outputs:
b) Write a program that demonstrates a high-priority thread using Sleep to give lower
priority threads a chance to run.
using System;
using System.Threading;
namespace PAD_lab_programs
{
classClass8b
{
staticpublicvoid Main()
{
// Creating and initializing threads
Thread T1 = new Thread(work);
Thread T2 = new Thread(work);
Thread T3 = new Thread(work);
// Set the priority of threads
T2.Priority = ThreadPriority.Highest;
T3.Priority = ThreadPriority.BelowNormal;
T1.Start();
T2.Start();
T3.Start();
// Display the priority of threads
Console.WriteLine("The priority of T1 is: {0}", T1.Priority);
Console.WriteLine("The priority of T2 is: {0}", T2.Priority);
Console.WriteLine("The priority of T3 is: {0}", T3.Priority);
}
publicstaticvoid work()
{
// Sleep for 1 second
Thread.Sleep(1000);
}
}
}
Three test outputs:
WEEK-10: DATE:
using System;
namespace lab_programs
{
public delegate string strmydel(string mystr);
//public delegate void strmydel1(string mystr);
class Testdelegate
{
public string space(string mystr)
{
mystr = mystr + "";
return mystr;
}
public string reverse(string mystr)
{
string rev = "";
rev = "";
Console.WriteLine("String is {0}", mystr);
int len;
len = mystr.Length - 1;
while (len >= 0)
{
rev = rev + mystr[len];
len--;
}
return rev;
}
static void Main()
{
string str, str1;
Console.WriteLine("enter a string");
str = Console.ReadLine();
Testdelegate t = new Testdelegate();
strmydel s = t.space;
str1 = s.Invoke(str);
Console.WriteLine("string after padding a space at the end" + str1);
strmydel s1 = t.reverse;
str1 = s1.Invoke(str);
Console.WriteLine(" after reversing the string" + str1);
}
}}
b) Implement a console application to get two integer numbers from user and perform
addition and multiplication on the input numbers. use the concept of MultiCastdelegates
using System;
using System.Collections.Generic;
using System.Text;
namespace lab_programs
{
delegate void dele(int a, int b);
public class Oper
{
public static void Add(int a, int b)
{
Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
}
public static void Sub(int a, int b)
{
Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
}
}
public class program
{
static void Main()
{
dele del = new dele(Oper.Add);
del += new dele(Oper.Sub);
del(4, 2);
del -= new dele(Oper.Sub);
del(1, 9);
Console.Read();
}
}
}
Three test outputs:
WEEK-11: DATE:
C:\ cd (give the path where the .dll file is present )\gacutil -i mydll.dll
namespace ClassLibrary
{
public class myClass
{
public string myFunction(string name)
{
return "Hello : " + name;
}
}
Using System
using ClassLibrary;
namespace ConsoleAPP
{
class Program
{
static void Main(string[] args)
{
myClass obj = new myClass();
Console.WriteLine(obj.myFunction("Sourav"));
Console.ReadLine();
}
}
Three test outputs:
b) Create a bank namespace with various classes (Saving , Current) and implement the
namespace in another application.
using System;
namespace first_space
{
class namespace_cl
{
public void Savings()
{
Console.WriteLine("Inside savings account in first_space");
}
}
}
namespace second_space
{
class namespace_cl
{
public void current ()
{
Console.WriteLine("Inside current account in second_space");
}
}
}
class TestClass
{
static void Main(string[] args)
{
first_space.namespace_cl fc = new first_space.namespace_cl();
second_space.namespace_cl sc = new second_space.namespace_cl();
fc.Savings();
sc.current();
Console.ReadKey();
}
}
Three test outputs:
WEEK-12: DATE:
a) Create a program to ask the user for data about books (title, author, gender and
summary) and store them in a SQLSERVER database
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlTest_CSharp
{
class Program
{
static void Main(string[] args)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = "Server=[server_name];
Database=[database_name];
Trusted_Connection=true";
conn.Open();
SqlCommand command = new SqlCommand("SELECT * FROM TableName WHERE
FirstColumn = @0", conn);
command.Parameters.Add(new SqlParameter("0", 1));
using (SqlDataReader reader = command.ExecuteReader())
{
Console.WriteLine("FirstColumn\tSecond Column\t\tThird Column\t\tForth Column\t");
while (reader.Read())
{
Console.WriteLine(String.Format("{0} \t | {1} \t | {2} \t | {3}", reader[0], reader[1],
reader[2], reader[3]));
}
}
Console.WriteLine("Data displayed! Now press enter to move to the next section!");
Console.ReadLine();
Console.Clear();
Console.WriteLine("INSERT INTO command");
SqlCommand insertCommand = new SqlCommand("INSERT INTO TableName
(FirstColumn, SecondColumn, ThirdColumn, ForthColumn) VALUES (@0, @1, @2, @3)",
conn);
insertCommand.Parameters.Add(new SqlParameter("0", 10));
insertCommand.Parameters.Add(new SqlParameter("1", "Test Column"));
insertCommand.Parameters.Add(new SqlParameter("2", DateTime.Now));
insertCommand.Parameters.Add(new SqlParameter("3", false));
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.Data.SqlClient;
public partial class _Default: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integ
rated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand("sp_insert", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Book Name", TextBox1.Text);
cmd.Parameters.AddWithValue("Author Name", TextBox2.Text);
cmd.Parameters.AddWithValue("Publication", TextBox3.Text);
con.Open();
int k = cmd.ExecuteNonQuery();
if (k != 0) {
lblmsg.Text = "Record Inserted Succesfully into the Database";
lblmsg.ForeColor = System.Drawing.Color.CornflowerBlue;
}
con.Close();
}
}
Three test outputs: