Wednesday 24 January 2018

How to make Magic Square in C-Language using 2-D array





#include <stdio.h>

#include <conio.h>



main()

{



int x[3][3]{{2,7,6},{9,5,1},{4,3,8}};

int row[3];

int col[3];

int d1=0,d2=0,i,j,flag=1;



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

{

row[i]=0;

col[i]=0;



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

{

row[i]=row[i]+x[i][j];

col[i]=col[i]+x[j][i];



if(i==j)

{

d1=d1+x[i][j];

}



if(i+j==2)

{

d2=d2+x[i][j];

}



} // inner loop end......



} //outer loop end











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

{



if(row[i]!=col[i])

{

flag=0;

break;

}



}



if(d1!=d2)

{

flag=0;

}



if(flag==0)

{



printf("It is not a magic square.....");

}

else

{

printf("It is a magic square.....");



}

















}

Thursday 18 January 2018

Learn C language Part -40 SQL ORACLE DATABASE STRUCTURE IN C LANGUAGE





#include <stdio.h>

#include <conio.h>

#include <string.h>

struct employee

{

int id ;

char name[50];

float salary;

char department[50] ;



};



main()



{





int i;

struct employee e1[5];



e1[0].id=101;



strcpy(e1[0].name,"Ali");



e1[0].salary=50000;



strcpy(e1[0].department,"HR");





//2ND RECORD..........................



e1[1].id=102;



strcpy(e1[1].name,"BILAL");



e1[1].salary=60000;



strcpy(e1[1].department,"IT");



//3rd RECORD..........................



e1[2].id=103;



strcpy(e1[2].name,"Daniyal");



e1[2].salary=40000;



strcpy(e1[2].department,"Marketing");



//3rd RECORD..........................



e1[3].id=104;



strcpy(e1[3].name,"Eraj");



e1[3].salary=30000;



strcpy(e1[3].department,"Admin");



//4th RECORD..........................



e1[4].id=105;



strcpy(e1[4].name,"faisal");



e1[4].salary=20000;



strcpy(e1[4].department,"Admin");







l1:



printf("\nID\tName\t\tSalary\t\tDepatment\t\n\n");



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

{

printf("\n-----------------------------------------------------------\n");

printf("%d\t%s\t\t%.2f\t\t%s\t",e1[i].id,e1[i].name,e1[i].salary,e1[i].department);

printf("\n");

}







printf("\n-----------------------------------------------------------\n");

printf("Enter the id: ");

int n;

scanf("%d",&n);



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

{



if(e1[i].id==n)

{



printf("\nID\tName\t\tSalary\t\tDepatment\t\n\n");

printf("\n-----------------------------------------------------------\n");

printf("%d\t%s\t\t%.2f\t\t%s\t",e1[i].id,e1[i].name,e1[i].salary,e1[i].department);



printf("\n");

n=-1;

break;

}



}



if(n!=-1)

{

printf("\n No Records found......");

}



printf("\nDo you want to continue......{y/n}\n");

char c;

scanf("%c",&c);

c=getchar();

if(c=='y')

{

printf("\n\n");

goto l1;

}













}

Learn C language Part 39 Structures in C language





#include <stdio.h>

#include <conio.h>

#include <string.h>

struct employee

{

int id ;

char name[50];

float salary;

char department[50] ;



};



main()

{



struct employee e1;

struct employee e2;



e1.id=101;

strcpy(e1.name,"Ali");

e1.salary=50000;

strcpy(e1.department,"HR");



//2ND RECORD..........................



e2.id=102;

strcpy(e2.name,"BILAL");

e2.salary=60000;

strcpy(e2.department,"IT");





//PRINTING........................



printf("Employee ID: %d\nName of Employee  : %s \nSalary:%f\nDepatment: %s",e1.id,e1.name,e1.salary,e1.department);



printf("Employee ID: %d\nName of Employee  : %s \nSalary:%f\nDepatment: %s",e2.id,e2.name,e2.salary,e2.department);













}

part 27-SQL injection and prevention In asp.net



backend code:

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;
using System.Configuration;

namespace WebApplication17
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        string cs = ConfigurationManager.ConnectionStrings["test"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string q = "select * from tblProductInventory";
                displayrecord(q);
            }
           
        }
        

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(cs);
            try
            {
                SqlCommand cmd = new SqlCommand("spsqlinjectionofproduct", con);
                cmd.Parameters.AddWithValue("@productname", TextBox1.Text);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                GridView1.DataSource = rdr;
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("ERROR IS FOUND " + ex);
            }
            finally
            {
                con.Close();
            }
           
            
        }



         public void displayrecord(string q)
        {

            SqlConnection con = new SqlConnection(cs);
            try
            {
                SqlCommand cmd = new SqlCommand(q, con);
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                GridView1.DataSource = rdr;
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("ERROR IS FOUND " + ex);
            }
            finally
            {
                con.Close();
            }

        }




    }
}

Front end code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication17.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" Width="268px"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" />

        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Height="441px" Width="861px">
            <AlternatingRowStyle BackColor="White" />
            <EditRowStyle BackColor="#7C6F57" />
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#E3EAEB" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F8FAFA" />
            <SortedAscendingHeaderStyle BackColor="#246B61" />
            <SortedDescendingCellStyle BackColor="#D4DFE1" />
            <SortedDescendingHeaderStyle BackColor="#15524A" />
        </asp:GridView>

        <h1>

            <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        </h1> 

    </div>
    </form>
</body>
</html>

web.config code:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>

<connectionStrings>
  <add name="test" connectionString="Data Source=faculty-35;Initial Catalog=ADODOTNET_LEARNING;Persist Security Info=True;User ID=sa;Password=aptech" providerName="System.Data.SqlClient"/>  

</connectionStrings>  

</configuration>



part 27-SQL injection and prevention In asp.net



backend code:

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;
using System.Configuration;

namespace WebApplication17
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        string cs = ConfigurationManager.ConnectionStrings["test"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string q = "select * from tblProductInventory";
                displayrecord(q);
            }
           
        }
        

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(cs);
            try
            {
                SqlCommand cmd = new SqlCommand("spsqlinjectionofproduct", con);
                cmd.Parameters.AddWithValue("@productname", TextBox1.Text);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                GridView1.DataSource = rdr;
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("ERROR IS FOUND " + ex);
            }
            finally
            {
                con.Close();
            }
           
            
        }



         public void displayrecord(string q)
        {

            SqlConnection con = new SqlConnection(cs);
            try
            {
                SqlCommand cmd = new SqlCommand(q, con);
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                GridView1.DataSource = rdr;
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("ERROR IS FOUND " + ex);
            }
            finally
            {
                con.Close();
            }

        }




    }
}

Front end code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication17.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" Width="268px"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" />

        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Height="441px" Width="861px">
            <AlternatingRowStyle BackColor="White" />
            <EditRowStyle BackColor="#7C6F57" />
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#E3EAEB" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F8FAFA" />
            <SortedAscendingHeaderStyle BackColor="#246B61" />
            <SortedDescendingCellStyle BackColor="#D4DFE1" />
            <SortedDescendingHeaderStyle BackColor="#15524A" />
        </asp:GridView>

        <h1>

            <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        </h1> 

    </div>
    </form>
</body>
</html>

web.config code:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>

<connectionStrings>
  <add name="test" connectionString="Data Source=faculty-35;Initial Catalog=ADODOTNET_LEARNING;Persist Security Info=True;User ID=sa;Password=aptech" providerName="System.Data.SqlClient"/>  

</connectionStrings>  

</configuration>



Wednesday 17 January 2018

Part-26 Sql Data Reader in asp.net with Try and Catch exception





back end code :



using System;

using System.Collections.Generic;

using System.Data.SqlClient;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;



namespace ADO1

{

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

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("Data Source=FACULTY-35;Initial Catalog=ADODOTNET_LEARNING;User ID=SA;Password=aptech");

            try

            {

                SqlCommand cmd = new SqlCommand("SELECT * FROM TBL_PRODUCT", con);

                con.Open();

                SqlDataReader rdr = cmd.ExecuteReader();

                GridView1.DataSource = rdr;

                GridView1.DataBind();

            }

            catch (Exception ex)

            {



                Response.Write("Error is " + ex);

            }

            finally

            {

                con.Close();

            }







        }

    }

}

Front end code :



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ADO1.aspx.cs" Inherits="ADO1.ADO1" %>



<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:GridView ID="GridView1" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">

            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />

            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />

            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />

            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />

            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />

            <SortedAscendingCellStyle BackColor="#FFF1D4" />

            <SortedAscendingHeaderStyle BackColor="#B95C30" />

            <SortedDescendingCellStyle BackColor="#F1E5CE" />

            <SortedDescendingHeaderStyle BackColor="#93451F" />

        </asp:GridView>

    </div>

    </form>

</body>

</html>

web.config code :

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  
    <connectionStrings>
      <add name="testdbms" connectionString="Data Source=FACULTY-35;Initial Catalog=ADODOTNET_LEARNING;User ID=SA;Password=aptech" providerName="System.Data.SqlClient"/>
    </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>

HOW ATM MACHINE WORKS (A prototype code in C language)





#include <stdio.h>

#include <conio.h>



main()

{

l3:

int amount[3]{1000,2000,3000};

int code[3]{1234,2134,5555};

int c,i,index=-1,input;

l1:

printf("Enter the Code: ");

scanf("%d",&c);



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

{



if(c==code[i])

{

index=i;

}





}



if(index==-1)

{

printf("\nINVALID CODE.......\nEnter the code again........\n");

goto l1;

}

l2:

printf("\n-------------------------------------\n");

printf("\t\twelcome to ATM");

printf("\n-------------------------------------\n");

printf("press 1 for Deposite Amount---->\n");

printf("press 2 for Cash With Drawl---->\n");

printf("press 3 for Check Balance---->\n");

scanf("%d",&input);



switch(input)

{



case 1:

printf("Enter the amount that you want to deposite : ");

int deposite;

scanf("%d",&deposite);

amount[index]=amount[index]+deposite;

printf("%d credited in your account %d \n",deposite,&amount[index]);

break;





case 2:

printf("Enter the amount that you want to draw : ");

int draw;

scanf("%d",&draw);

if(draw>amount[index])

{

printf("YOU ARE EXCEEDING YOUR BALANCE AMOUNT......\n");

}

else{



amount[index]=amount[index]-draw;

printf("%d credited in your account %d \n",draw,&amount[index]);

}

break;





case 3:

printf("Your Balance Amount is %d",amount[index]);

break;



default:





break;



}





printf("\nDo you want to Continue.....(y/n)\n");

char e;

e=getchar();

scanf("%c",&e);

if(e=='y')

{

goto l2;

}

else

{

index=-1;

goto l3;

}



}

Tuesday 16 January 2018

Learn C language Part 38 Pointers of Pointers in C language





#include <stdio.h>

#include <conio.h>



main()

{



int value=100;

int *ptr;

int **pofptr;





ptr=&value;

pofptr=&ptr;





printf("value of variable is %d \n",value);

printf("value of variable through ptr %d \n",*ptr);

printf("value of variable through pofptr %d ",**pofptr);











}

Learn C language Part 38 Pointers of Pointers in C language





#include <stdio.h>

#include <conio.h>



main()

{



int value=100;

int *ptr;

int **pofptr;





ptr=&value;

pofptr=&ptr;





printf("value of variable is %d \n",value);

printf("value of variable through ptr %d \n",*ptr);

printf("value of variable through pofptr %d ",**pofptr);











}

Learn C language Part 37 Arrays of Pointers in C language





#include <stdio.h>

#include <conio.h>



main()

{



int x[3]{100,200,300};

int i=0;

int *ptr[3];



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

{

ptr[i]=&x[i];

}







printf("\nWithout pointers\n...............................\n");



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

{



printf("values at index %d = x[%d] \n",i,x[i]);



}



printf("\nWith pointers\n...............................\n");



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

{



printf("values at index %d = x[%d] is saved at @ %d, address of array is %d  \n",i,*ptr[i],&ptr[i],ptr[i]);



}









}

Monday 15 January 2018

Part-25 (Object Data Source with Gridview binding in asp.net)



Employee Class

 public class Employee
    {
        public int id { get; set; }
        public string Name { get; set; }
        public string Gender { get; set; } 
        public string DeptName { get; set; }


    }

EmployeeData access layer Class

 public class EmployeeDATAACCESSLAYER
    {


        public static List<Employee> GetAllemployee()
        {
            List<Employee> employees = new List<Employee>();

            string CS = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("select id,Name,Gender,DeptName from tblEmployees", con);
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    Employee emp = new Employee();
                    emp.id = Convert.ToInt32(rdr["id"]);
                    emp.Name = rdr["Name"].ToString();
                    emp.Gender = rdr["Gender"].ToString();
                    emp.DeptName = rdr["DeptName"].ToString();
                    employees.Add(emp);

                }

            }

            return employees;
        }// method end.......................................


    }

Sunday 14 January 2018

Learn C language Part 36 Arithmetic Operation on Pointers







#include <stdio.h>

#include <conio.h>



main()

{

int a=5,i;



int *ip;



ip=&a;



printf("Address of A : %d",&a);

printf("\nValue in Ip : %d",ip);

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

{



ip++;

printf("\nVarible %d =  %d",i,ip);





}









}

Learn C language Part 35 Easy & WorkinG Example of Pointers in C





#include <stdio.h>

#include <conio.h>



main()

{



int a=10;

int *ip;



ip=&a;



printf("Address of A :%d ",&a);

printf("\nValue in Ip : %d",ip);

printf("\nAddres of Ip : %d",&ip);

printf("\nValue of Ip : %d",*ip);











}

Learn C language Part 34 Introduction to Pointers





#include <stdio.h>

#include <conio.h>



main()

{



int a=10,b=0,c;





printf("Address of A: %d",&a);



printf("\nAddress of B: %d",&b);



printf("\nAddress of C: %d",&c);

















}

Learn C language Part 34 Introduction to Pointers





#include <stdio.h>

#include <conio.h>



main()

{



int a=10,b=0,c;





printf("Address of A: %d",&a);



printf("\nAddress of B: %d",&b);



printf("\nAddress of C: %d",&c);

















}

Friday 12 January 2018

(Part-22){Client and Server Side Validation,Email Regular Expression Val...





WEBFORM .ASPX CODE


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="comparefieldvalid.aspx.cs" Inherits="WebApplication13.comparefieldvalid" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            width: 159px;
        }
        .auto-style3 {
            width: 159px;
            height: 31px;
        }
        .auto-style4 {
            height: 31px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        
    
        <table class="auto-style1">
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label1" runat="server" Text="Email"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" Width="233px"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid Email Format" ControlToValidate="TextBox1" Display="Dynamic" ForeColor="#CC0000" ValidationExpression="^(?(&quot;&quot;)(&quot;&quot;.+?&quot;&quot;@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&amp;'\*\+/=\?\^`\{\}\|~\w])*)(?&lt;=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"></asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Email is Reuqired" ForeColor="#CC0000"></asp:RequiredFieldValidator>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3">
                    <asp:Label ID="Label2" runat="server" Text="Re type Email"></asp:Label>
                </td>
                <td class="auto-style4">
                    <asp:TextBox ID="TextBox2" runat="server" Width="233px"></asp:TextBox>
                    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox1" ControlToValidate="TextBox2" ErrorMessage="Email  doesnot Match" ForeColor="#CC0000" Display="Dynamic"></asp:CompareValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" Display="Dynamic" ErrorMessage="Retype Email is Reuqired" ForeColor="#CC0000"></asp:RequiredFieldValidator>
                </td>
                <td class="auto-style4"></td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label3" runat="server" Text="Password"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox3" runat="server" Width="233px" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3" Display="Dynamic" ErrorMessage="Passowrd is Reuqired" ForeColor="#CC0000"></asp:RequiredFieldValidator>
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label4" runat="server" Text="Confirm Password"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox4" runat="server" Width="233px" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox4" Display="Dynamic" ErrorMessage="Retpye Passowrd is Reuqired" ForeColor="#CC0000"></asp:RequiredFieldValidator>
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>

        
    
    </div>
      
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
           
    </form>
</body>
</html>

WEBFORM .ASPX.CS CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication13
{
    public partial class comparefieldvalid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Response.Write("Email approved");
            }
        }
    }
}

WEB.CONFIG CODE

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>



 <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
</configuration>


(Part-22){Client and Server Side Validation,Email Regular Expression Val...





WEBFORM .ASPX CODE


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="comparefieldvalid.aspx.cs" Inherits="WebApplication13.comparefieldvalid" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            width: 159px;
        }
        .auto-style3 {
            width: 159px;
            height: 31px;
        }
        .auto-style4 {
            height: 31px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        
    
        <table class="auto-style1">
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label1" runat="server" Text="Email"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" Width="233px"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid Email Format" ControlToValidate="TextBox1" Display="Dynamic" ForeColor="#CC0000" ValidationExpression="^(?(&quot;&quot;)(&quot;&quot;.+?&quot;&quot;@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&amp;'\*\+/=\?\^`\{\}\|~\w])*)(?&lt;=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"></asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Email is Reuqired" ForeColor="#CC0000"></asp:RequiredFieldValidator>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3">
                    <asp:Label ID="Label2" runat="server" Text="Re type Email"></asp:Label>
                </td>
                <td class="auto-style4">
                    <asp:TextBox ID="TextBox2" runat="server" Width="233px"></asp:TextBox>
                    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox1" ControlToValidate="TextBox2" ErrorMessage="Email  doesnot Match" ForeColor="#CC0000" Display="Dynamic"></asp:CompareValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" Display="Dynamic" ErrorMessage="Retype Email is Reuqired" ForeColor="#CC0000"></asp:RequiredFieldValidator>
                </td>
                <td class="auto-style4"></td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label3" runat="server" Text="Password"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox3" runat="server" Width="233px" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3" Display="Dynamic" ErrorMessage="Passowrd is Reuqired" ForeColor="#CC0000"></asp:RequiredFieldValidator>
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label4" runat="server" Text="Confirm Password"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox4" runat="server" Width="233px" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox4" Display="Dynamic" ErrorMessage="Retpye Passowrd is Reuqired" ForeColor="#CC0000"></asp:RequiredFieldValidator>
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>

        
    
    </div>
      
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
           
    </form>
</body>
</html>

WEBFORM .ASPX.CS CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication13
{
    public partial class comparefieldvalid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Response.Write("Email approved");
            }
        }
    }
}

WEB.CONFIG CODE

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>



 <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
</configuration>


(Part-21){Client and Server Side Validation,Compare Field Validator in a...







WEBFORM .ASPX CODE

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="comparefieldvalid.aspx.cs" Inherits="WebApplication13.comparefieldvalid" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            width: 159px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        
    
        <table class="auto-style1">
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label1" runat="server" Text="Email"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" Width="233px"></asp:TextBox>
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label2" runat="server" Text="Re type Email"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server" Width="233px"></asp:TextBox>
                    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox1" ControlToValidate="TextBox2" ErrorMessage="Email  doesnot Match" ForeColor="#CC0000"></asp:CompareValidator>
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style2">&nbsp;</td>
                <td>
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style2">&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        </table>

        
    
    </div>
    </form>
</body>
</html>

WEBFORM .ASPX.CS CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication13
{
    public partial class comparefieldvalid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Response.Write("Email approved");
            }
        }
    }
}

WEB.CONFIG CODE:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>



 <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
</configuration>

(Part-21){Client and Server Side Validation,Compare Field Validator in a...







WEBFORM .ASPX CODE

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="comparefieldvalid.aspx.cs" Inherits="WebApplication13.comparefieldvalid" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            width: 159px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        
    
        <table class="auto-style1">
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label1" runat="server" Text="Email"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" Width="233px"></asp:TextBox>
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label2" runat="server" Text="Re type Email"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server" Width="233px"></asp:TextBox>
                    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox1" ControlToValidate="TextBox2" ErrorMessage="Email  doesnot Match" ForeColor="#CC0000"></asp:CompareValidator>
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style2">&nbsp;</td>
                <td>
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style2">&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        </table>

        
    
    </div>
    </form>
</body>
</html>

WEBFORM .ASPX.CS CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication13
{
    public partial class comparefieldvalid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Response.Write("Email approved");
            }
        }
    }
}

WEB.CONFIG CODE:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>



 <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
</configuration>

Wednesday 10 January 2018

(Part-20){Client and Server Side Validation,Range Field Validator in asp...







Jquery Link

copy and paste this code b/w head tag:

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"  
type="text/javascript"></script>   
<!--include jQuery Validation Plugin-->  
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js"  
type="text/javascript"></script>  

calendar hide/show code :

copy and paste this code b/w head tag:

    <script>
    $(document).ready(function ()
    {
        $("#calbtn").click(function ()
        {
            $("#Calendar1").toggle();
    });
});
</script>

Web.config Code :

copy and paste the following code b/w configuration tag :


  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>

(Part-19){Client and Server Side Validation,Required Field Validator in ...





Jquery Link

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"  
type="text/javascript"></script>   
<!--include jQuery Validation Plugin-->  
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js"  
type="text/javascript"></script>  

web. Config setting :

copy and paste the following code between the configuration tag

 <appSettings>
      <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    </appSettings>

Tuesday 9 January 2018

Learn C language Part 33 Reverse source string into Destination string





#include <stdio.h>

#include <conio.h>



main()

{

char c[50];

char d[50];

int l=0,i=0,h;

printf("Enter the string : ");

gets(c);



while(c[l]!='\0')

{



l++;

}

h=l;

h--;



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

{



d[h]=c[i];

h--;

}

d[l]='\0';



puts(d);



}

Learn C language Part 32 Compare String Program {Checking two input str...



#include <stdio.h>

#include <conio.h>



main()

{

char c[50];

char d[50];

int i=0,flag=0;

printf("Enter the 1st String : ");

gets(c);



printf("\nEnter the 2nd String : ");

gets(d);





while(c[i]!='\0')

{



if(c[i]!=d[i])

{

flag=1;

break;

}

i++;

}



if(flag==0)

{

printf("both strings are equal!");

}

else

{

printf("both strings are not equal!");



}

}

Monday 8 January 2018

Learn ASP.NET web from in urdu/hindi (Part-17){Multi view Control in asp...







<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication10.WebForm1" %>



<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>



    <style>



       table

        {

           border:3px solid red;

        }



    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>



        <asp:MultiView ID="MultiView1" runat="server">



            <asp:View ID="View1" runat="server">

                <table>



                    <tr>

                         <td> <asp:Label ID="Label1" runat="server" Text="Email"></asp:Label></td>

                       

                         <td>

                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td>



                    </tr>

                   

                    <tr>

                         <td> <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label></td>

                       

                         <td>

                        <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox> </td>



                    </tr>



                    <tr>

                        <td> </td>

                        <td> <asp:Button ID="Button1" runat="server" Text="NEXT->" OnClick="Button1_Click" /></td>

                       



                    </tr>

                </table>

            </asp:View>



            <%--1st view end.....-------------------------------------------------------------.--%>

            <asp:View ID="View2" runat="server">





                      <table>



                    <tr>

                         <td> <asp:Label ID="Label3" runat="server" Text="Name"></asp:Label></td>

                       

                         <td>

                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </td>



                    </tr>

                   

                    <tr>

                         <td> <asp:Label ID="Label4" runat="server" Text="Gender"></asp:Label></td>

                       

                         <td>

                             <asp:DropDownList ID="DropDownList1" runat="server">

                                 <asp:ListItem>Male</asp:ListItem>

                                 <asp:ListItem>Female</asp:ListItem>

                             </asp:DropDownList>

                        </td>



                    </tr>



                    <tr>

                        <td> <asp:Button ID="Button3" runat="server" Text="Back<-" OnClick="Button3_Click" /></td>

                        <td> <asp:Button ID="Button2" runat="server" Text="NEXT->" OnClick="Button2_Click" /></td>

                       



                    </tr>

                </table>









            </asp:View>





              <%--2nd view end.....-------------------------------------------------------------.--%>

            <asp:View ID="View3" runat="server">



                 <table>



                    <tr>

                         <td> <asp:Label ID="Label5" runat="server" Text="Email"></asp:Label></td>

                       

                         <td>

                          <asp:Label ID="lblemail" runat="server" Text=""></asp:Label>

                         </td>



                    </tr>

                   

                    <tr>

                         <td> <asp:Label ID="Label6" runat="server" Text="Name"></asp:Label></td>

                       

                         <td>

                            <asp:Label ID="lblname" runat="server" Text=""></asp:Label>

                        </td>



                    </tr>



                          <tr>

                         <td> <asp:Label ID="Label7" runat="server" Text="Gender"></asp:Label></td>

                       

                         <td>

                            <asp:Label ID="lblgender" runat="server" Text=""></asp:Label>

                        </td>



                    </tr>







                    <tr>

                        <td> <asp:Button ID="Button4" runat="server" Text="Back<-" OnClick="Button4_Click" /></td>

                        <td> <asp:Button ID="Button5" runat="server" Text="NEXT->" OnClick="Button5_Click" /></td>

                       



                    </tr>

                </table>











            </asp:View>















        </asp:MultiView>

   

    </div>

    </form>

</body>

</html>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication10
{
    public partial class WebForm1 : System.Web.UI.Page
    {
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MultiView1.ActiveViewIndex = 0;
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //next -1
            
            MultiView1.ActiveViewIndex = 1;

            

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
           
            MultiView1.ActiveViewIndex = 2;

            lblemail.Text = TextBox1.Text;
            lblgender.Text =DropDownList1.SelectedItem.ToString() ;
            lblname.Text = TextBox3.Text;

            //next -2
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            //back-1
            MultiView1.ActiveViewIndex = 0;
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            //submit
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            //back-2
            MultiView1.ActiveViewIndex = 1;
        }
    }
}

Sunday 7 January 2018

Learn C language Part 31 Count Frequency of a Character in string





#include <stdio.h>

#include <conio.h>



main()

{



char c[50];

char d;

int i=0,sum=0;



printf("Enter your Name : ");

gets(c);

printf("\nEnter your Searching Character : ");

d=getchar();





while(c[i]!='\0')

{



if(c[i]==d)

{

sum=sum+1;

}

i++;



}





printf("\n\n%c is found %d times in string",d,sum);









}

Learn C language Part 30 Gets and Puts String Method in C





#include <stdio.h>

#include <conio.h>



main()

{



char name[50];

printf("Enter your Name: ");

gets(name); //read string...



printf("Your Name is : ");

puts(name); //print .....



}

Learn C language Part 29 Read String From Use Input using while loop





#include <stdio.h>

#include <conio.h>



main()

{



char name[50];

char c;

int i=0;

printf("Enter your Name: ");



while(c!='\n')

{



c=getchar();

name[i]=c;

i++;



}



name[i]='\0';





printf("name : %s",name);







}

Friday 5 January 2018

How to Check input is Alphabet or not





#include <stdio.h>

#include <conio.h>



main()

{



char c;

printf("Enter a character: ");

scanf("%c",&c);





if((c>='a'&& c<='z') || (c>='A'&& c<='Z')  )

{

printf("%c is an alphabet",c);



}

else

{

printf("%c is not an alphabet",c);



}











}

How to Find a year is a leap year





#include <stdio.h>

#include <conio.h>



main()

{



int year;



printf("Enter the year: ");

scanf("%d",&year);



if(year%4==0)

{



printf("%d is a leap year",year);

}



else

{

printf("%d is a not leap year",year);



}















}

How to Check a number is Even or Odd



#include <stdio.h>

#include <conio.h>





main()

{

int n;



printf("ENTER A NUMBER: ");

scanf("%d",&n);



if(n%2==0)

{

printf("%d is an even number",n);

}



else

{

printf("%d is an Odd number",n);



}







}



//2,4,6,8,10,....even

//1,3,5,7,9...... odd


Thursday 4 January 2018

Learn C language Part 28 String Introduction in C Language



#include <stdio.h>

#include <conio.h>



main()

{



char c[]="abcd\\ndef";

char d[4]="abc";



char e[] = {'a', 'b', 'c', 'd', '\0'};

     OR,

char f[5] = {'a', 'b', 'c', 'd', '\0'};



printf("%s",&c);



printf("\n%s",&d);







}


Learn C language Part 27 Function by reference





#include <stdio.h>

#include <conio.h>



void calculator(float a,float b,float *plus,float *diff, float *product, float *divide);



main()

{



float add,sub,mul,div;

float a=32.1, b=10.9;

calculator(a,b,&add,&sub,&mul,&div);



printf("Sum = %f\n",add);

printf("Difference = %f \n",sub);

printf("Product = %f \n",mul);

printf("quotient = %f \n",div);









}



void calculator(float a,float b,float *plus,float *diff, float *product, float *divide)

{

*plus= a+b;

*diff= a -b;

*product=a*b;

*divide=a/b;



}


Tuesday 2 January 2018

Learn C language Part 26 How to find multiple items in array in C





#include <stdio.h>

#include <conio.h>



main()

{

int i,v=1,flag=0;

int x[5];

x[0]=32;

x[1]=1;

x[2]=32;

x[3]=12;

x[4]=32;



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

{



if(x[i]==v)

{

printf("%d is found at index %d\n",v,i);

flag=1;

}



if(flag==0 && i==4)

{

printf("%d doesnt exist in the array ",v);

}



}























}

Learn C language Part 25 How to make Reverse Search Function in C





code link :



#include <stdio.h>

#include <conio.h>



int search(int x[],int value);

int revsearch(int x[],int value);

main()



{



int x[6]{11,32,76,32,32,54};







int v;



printf("Enter the number that you want to search =");



scanf("%d",&v);







int s=revsearch(x,v);



if(s==-1)



{



printf("%d doesnot exist in the array",v);



}



else



{



printf("%d is found at %d index",v,s);











}



//main meth0d end...........





int search(int x[],int value)



{





int i,t=-1;



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



{



if(x[i]==value)



{



t=i;



break;



}



}



return t;





}//method end search........................................







int revsearch(int x[],int value)



{





int i,t=-1;



for(i=5;i>=0;i--)



{



if(x[i]==value)



{



t=i;



break;



}



}



return t;





}//method end search........................................

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...