What is ASP.
Net
• ASP.Net is a server-side technology for web development.
• It is provided by Microsoft.
• ASP.Net was first released in the year 2002.
• The full form of ASP is ActiveX Server Pages, and .NET is Network Enabled Technologies.
• This framework is used for developing a powerful dynamic web sides, web application
and web services.
1) What is the difference between the ASP and
ASP.NET?
• ASP.NET:
• ASP.Net support windows platform only.
• ASP.Net is High performing framework.
• Architecture of ASP.Net is Based on .Net framework only.
• ASP.NET CORE:
• ASP.Net Core support windows, Linux and MAC OS Platform.
• ASP.Net Core is Better Performance than ASP.Net
• Architecture of ASP.Net Core is Based on .Net & .Net Core framework.
3)ASP.Net Connection String Syntax in Configuration
file.
• Syntax: -
<connectionStrings>
<add name=” DBCS” connectionString=”” providerName=”
System.Data.SqlClient”/>
<\connectionStrings>
4) ASP.Net connectionString Syntax in .CS File.
• Syntax: -
String cs = ConfigurationManager.ConnectionStrings[“DBCS”].ConnectionStrings;
5) This is the Command to Insert Data in Table
(Database).
• Syntax: -
String cs = ConfigurationManager.ConnectionStrings[“DBCS”].ConnectionString;
SqlConnection con = new SqlConnection(cs);
con.Open();
String query = “select * form login where username = @ user and password = @pass”;
SqlCommand cmd = new SqlCommand(query, con);
cmd.parameters.AddWithValue(“@user”, TextBox1.Text);
cmd.parameters.AddWithValue(“@pass”, TextBox2.Text);
cmd.ExecuteNonQuery();
con.Close();
Messagebox.Show(“Successfully Saved”);
6) This is the another way to write a Command to
Insert Data in Table (Database).
Syntax: -
String cs = ConfigurationManager.ConnectionStrings[“DBCS”].ConnectionString;
string query = "select * from login where username = @user and password = @pass";
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("@user", TextBox1.Text);
cmd.Parameters.AddWithValue("@pass", TextBox2.Text);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
MessageBox.Show("Login Successful");
}
else
{
MessageBox.Show("Invalid Username or Password");
}
}
7) CRUD Operation command With SQL Syntax.
• // Create
• string createQuery = "insert into login (username, password) values (@user, @pass)";
• // Read
• string readQuery = "select * from login where username = @user and password = @pass";
• // Update
• string updateQuery = "update login set password = @newPass where username = @user";
• // Delete
• string deleteQuery = "delete from login where username = @user";
8) To Jump another page use this Syntax.
• Response.Redirect(“DASHBOART.aspx”);
9) Find Armstrong Number in C# Programing?
• using System;
namespace Armstrong
{
class program
{
public static void Main(string[] args)
{
int temp, num, rem, sum=0;
Console.WriteLine("Enter your Number : ");
num = Convert.ToInt32(Console.ReadLine());
temp = num;
while(temp > 0)
{
rem = temp % 10;
sum = sum + rem * rem * rem;
temp = temp / 10;
}
if(sum == num)
{
Console.WriteLine("Armstrong Number");
}
else
{
Console.WriteLine("Not Armstrong Number");
}
}
}
}
10) Find Palindrome Number In C#?
• using System;
namespace Palindrome
{
class program
{
public static void Main(string[] args)
{
int temp, num, sum=0, rem;
Console.WriteLine("Enter your number: ");
num = Convert.ToInt32(Console.ReadLine());
temp = num ;
while(temp > 0)
{
rem = temp % 10;
sum = sum * 10 + rem;
temp = temp / 10;
}
if( sum == num)
{
Console.WriteLine("Palindrome Number");
}
else{
Console.WriteLine("Not Palindrome Number");
}
}
}
}
11) Count How Many Words in your String.
• using System;
namespace demo
{
class program
{
public static void Main(string[] args)
{
string str1;
int count=1, len=0;
Console.WriteLine("Enter your string");
str1 = Console.ReadLine();
while(len < str1.Length)
{
if(str1[len] == ' ' || str1[len] == '\n' || str1[len] == '\t')
{
count++;
}
len++;
}
Console.WriteLine("{0} words in your string ", count);
}
}
}
12) Find the second or First largest Number?
• using System;
namespace demo
{
class program
{
public static void Main(string[] args)
{
int max1, max2;
int[] arr = {12,78,56,32,19,46,72,58};
for(int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
max1 = max2 = arr[0];
for(int i = 0; i < arr.Length; i++)
{
if(arr[i] > max1)
{
max2 = max1;
max1 = arr[i];
}
else if(arr[i] > max2){
max2 = arr[i];
}
}
Console.WriteLine("\n{0} is the First Maximum number ", max1);
Console.WriteLine("\n{0} is the Second Maximum number ", max2);
}
}
}
13) Find How Many Duplicate Elements in Your
Array.
• using System;
using System.Collections.Generic;
namespace demo
{
class Program
{
public static void Main(string[] args)
{
int[] arr = { 10, 5, 10, 2, 5, 4, 5 };
var dict = new Dictionary<int, int>();
foreach (var value in arr)
{
if (dict.ContainsKey(value))
{
dict[value]++;
}
else
{
dict[value] = 1;
}
}
foreach (var pair in dict)
{
Console.WriteLine("{0} = {1} time", pair.Key, pair.Value);
}
}
}
}
14) Print Fibonacci Series in C#.
• using System;
namespace demo
{
class program
{
public static void Main(string[] args)
{
int num1=0, num2=1, num3, range;
Console.WriteLine("Enter your number : ");
range = Convert.ToInt32(Console.ReadLine());
Console.Write(num1+" ");
//Console.Write(num2+" ");
while(range > 1)
{
num3 = num1 + num2;
Console.Write(num3+" ");
num1 = num2;
num2 = num3;
range--;
}
}
}
}
15) Remove Duplicate Elements from the Array.
• using System;
using System.Linq; // Required to use Distinct()
namespace demo
{
class program
{
public static void Main(string[] args)
{
int[] arr = {4,5,3,9,2,65,4,2,8,5,3,5,4};
Console.WriteLine("\nOrignal Array Elements.");
foreach(var item1 in arr)
{
Console.Write(item1 + " ");
}
Console.WriteLine("\n");
int[] RemoveDuplicate = arr.Distinct().ToArray();
Console.WriteLine("\n After Remove your duplicate array elements.");
foreach(var item in RemoveDuplicate)
{
Console.Write(item + " ");
}
}
}
}