NOTES

Thursday 30 June 2011

ASP.NET Code Only


Four Type Connection String Pass In Sql

 With Out Argument
Class Lavel Declare
{
SqlConnection con;
SqlCommand cmd;
}

Constractor Part()
{
con=new SqlConnection("datasource=.\\sqlexpress;initial catalog=database_name; integrated security=sspi");
}

Function Part()
{
cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandText="Pass The Query "
}

 Single Argument Pass
Class Lavel Declare
{
SqlConnection con;
SqlCommand cmd;
}

Constractor Part()
{
con=new SqlConnection("datasource=.\\sqlexpress;initial catalog=database_name; integrated security=sspi");
}

Function Part()
{
cmd.Connection=con;
cmd=new SqlCommand("Pass The Query");
}

Double Argument


Class Lavel Declare
{
SqlConnection con;
SqlCommand cmd;
}

Constractor Part()
{
con=new SqlConnection("datasource=.\\sqlexpress;initial catalog=database_name; integrated security=sspi");
}

Function Part()
{
cmd=new SqlCommand("Pass The Query", con);
}

GRIED VIEW

IMAGE LOAD IN DATA BASE AND SHOW IN GRIDVIEW

ASPX PAGE CODE :::::::

<asp:GridView ID="g1" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:TemplateField>
    <HeaderTemplate>IMAGE
    </HeaderTemplate>
    <ItemTemplate>
    <asp:Image ID="imd" runat="server" ImageUrl='<%# bind("image") %>' Height="20%" Width="30%" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />


.CS Page Code :::

using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataReader rd;
    DataTable dt;
    SqlDataAdapter da;
    public _Default()
    {
        con = new SqlConnection("data source=.\\sqlexpress; initial catalog=demo1; integrated security=SSPI; ");
        dt = new DataTable();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fill();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        con.Open();
            FileUpload1.SaveAs(Server.MapPath("a/")+FileUpload1.FileName);
            cmd = new SqlCommand("insert into img values('" + "a/" + FileUpload1.FileName + "')", con);
        int i =cmd.ExecuteNonQuery();
        if (i != 0)
        {
            fill();
        }

    }
    public void  fill()
    {
               da = new SqlDataAdapter("select * from img", con);
            da.Fill(dt);
            g1.DataSource = dt;
            g1.DataBind();
    }
}



Useing CheckBox Delete The Data Form GriedView

ASPX PAGE CODE :::::::

 <asp:GridView ID="g1" runat="server" AutoGenerateColumns="false"
                               OnRowDeleting="delete">
    <Columns>
    <asp:TemplateField>
    <HeaderTemplate>
    <asp:Button ID="b1" runat="server" Text="DELETE" CommandName="delete" /><br />
    <asp:CheckBox ID="all" runat="server" AutoPostBack="true" OnCheckedChanged="All_Check" />
    </HeaderTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="one" runat="server" AutoPostBack="true" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <HeaderTemplate> IMAGE</HeaderTemplate>
    <ItemTemplate>
    <asp:Label ID="l1" runat="server" Text='<%#bind("image") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>

.CS Page Code :::

using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("data source=.\\sqlexpress; initial catalog=demo1; integrated security=SSPI");
    SqlCommand cmd;
    SqlDataReader rd;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fill();
        }
    }
    public void All_Check(object sender, EventArgs e)
    {
        CheckBox All = g1.HeaderRow.FindControl("all") as CheckBox;
        for (int i = 0; i < g1.Rows.Count; i++)
        {
            CheckBox One = g1.Rows[i].FindControl("one") as CheckBox;
            if (All.Checked == true)
            {
                One.Checked = true;
            }
            else
            {
                One.Checked = false;
            } 
        }
    }
    public void fill()
    {
        con.Open();
        cmd = new SqlCommand("select * from img", con);
        rd=cmd.ExecuteReader();

        rd.Read();
        g1.DataSource = rd;
        g1.DataBind();
        con.Close();
    }
    protected void delete(object sender, GridViewDeleteEventArgs e)
    {
        for (int k = 1; k < g1.Rows.Count; k++)
        {
            CheckBox One = g1.Rows[k].FindControl("one") as CheckBox;
            if (One.Checked == true)
            {
                Label l=g1.Rows[k].FindControl("l1") as Label;
                con.Open();
                cmd = new SqlCommand("delete from img where image='" + l.Text + "'", con);
                cmd.ExecuteNonQuery();
                con.Close();
            }
        }
        fill();
    }





STATEMANEGMENT

COOKIES SYNTAX  :::::

Create Single Value In Cookies :::::

Buttom code :::  Cookies Has Single Value
HttpCookie c = new HttpCookie("c1");
c.Value = TextBox1.Text;
c.Expires = System.DateTime.Now.AddHours(3);
Request.Cookies.Add(c);
Response.Redirect("Default2.aspx");


Next Page Load event Code::
if (!IsPostBack)
        {
            Response.Write(Request.Cookies["c1"].Value.ToString());
        }

End Cookies Code :::::

Create Multi Value In Cookies :::::::
HttpCookie aCookie = new HttpCookie("userInfo");
aCookie.
Values["userName"] = "patrick";
aCookie.
Values["lastVisit"] = DateTime.Now.ToString();
aCookie.
Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);
Response.Redirect("Default2.aspx");


Next Page Load event Code::  

      if (!IsPostBack)
         {
          Response.Write(Request.Cookies["userInfo"]["userName"]);            Response.Write(Request.Cookies["userInfo"]["lastVisit"]);
          }

End Cookies Code



MAILING CODE
Code Past ON Button  :::::


 MailMessage m = new MailMessage(From, To, Subject Text, Body Text);
            try
            {
                NetworkCredential n = new NetworkCredential("Your ID", "PassWord");
                SmtpClient s = new SmtpClient("smtp.gmail.com", 587);
                s.EnableSsl = true;
                s.UseDefaultCredentials = false;
                s.Credentials = n;
                s.Send(m);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }





Labels:

C++

Print Array Types

#include<iostream.h>
#include<conio.h>
void main()
{
int a[]={11,12,13,14,15};
int i;
for(i=0; i<5;i++)
{
cout<<a[i]<<i[a]<<*(a+i)<<*(i+a);
}
getch();
}

Labels:

SQL DATA

Find Top Value In a Table Column

create table ctr
(
num  int
 )

insert into ctr values(1)
insert into ctr values(2)
insert into ctr values(3)
insert into ctr values(4)
insert into ctr values(5)
insert into ctr values(33)
insert into ctr valuse(63)

select top 1 num from(select top 3 num from ctr  order by num desc) ctr order by num desc

OutPut Is 63

Add New Column In the Table

alter table table_name add column_name datatypewithsize


Mdify Column In the Table

alter table table_name alter  column column_name datatypewithsize


Create Sub Table Use The An Other Table

select columns_names into new_Table_Name from Old_Table_Name


Create Table Using Constraints


create table emp
(
id int primary key,
name varchar(10) null,
city varchar(10) check(city in('ORAI','BHOPAL'))
)

create table dept
(
d_id int primary key,
e_id int references emp(id),
d_name varchar(30) not null
)

If You Want To Add Constraint After Create Table



create table emp
(
id int ,
name varchar(10),
city varchar(10) )

create table dept
(
d_id int,
e_id int,
d_name varchar(30)
)

Follow Some Point :::

1- If we Want to add the primary key in the column than first add the not null constraint  in the table tha after add  the primary key.....

Syntax is :::
              alter table emp1 alter column  id  int  not null
              alter table emp1 add constraint  i  primary key(id)i ==  Is Constraint Name


2-Add the foreign key in the table than follow this

Syntax :::
      alter table dept1 add constraint ii  foreign key(e_id)  references emp1(id)

ii ==  Is Constraint Name       

3- add the check consteaint
    table emp1 add constraint iiii check(city in('orai','kanpur'))
iiii ==  Is Constraint Name       

Some Other Quries  


create datebase database_name
use database database_name

drop table table_name
truncae table table_name
delete from  table_name

drop command drop the stracture but truncate command delete the table data


alter

Labels:

Tuesday 28 June 2011

Overloading

·        Its Compile time polymorohism.
·        It’s use to add the  two user defined data type such as Object.
·        It is the class member function (means that non-static fuction).
·        Does not support automatic  Type Converions for the use defined data type.C++ hanhles The convertion Of Fundamantal Data Type  We use the  Type costing operator function.
·        It  is the publicl part of the class.
·        Create a class the defined the datatype that is used in the Opreator overload operation.
·        oveloading operator must have at leat one user defined data type.

C#

Reflection

            Assembly Contain the four Filed

·         Main-Fest
·         Matadata
·         IL
·         REsources


MANI-FEST
        An assembly manifest contains The first four items
·          the assembly name,
·          version number,
·          Culture
·          strong name information - make up the assembly's identity.

 Assembly name: A text string specifying the assembly's name.
 Version number: A major and minor version number, and a revision and build number. The common language runtime uses these numbers to enforce version policy.

 Culture: Information on the culture or language the assembly supports. This information should be used only to designate an assembly as a satellite assembly containing culture- or languagespecific information. (An assembly with culture information is automatically assumed to be a satellite assembly.)

 Strong name information: The public key from the publisher if the assembly has been given a strong name.







Create Shared Assembly

· First Create The  Strong Key Name
  Syntax Is:
                  C:\     Sn –k a.snk     
                 by Defualt Store In C:\\

·Second Create the  .cs file
using System;
using System.Reflection;                                                                      
[assembly:AssemblyKeyFile("c:\\amit\\a.snk")]

public class amit
{
public string show()
{
return "AMIT KUMAR GUPTA";
}

public int add()
{
int i,j,k;
Console.WriteLine("enter first number");
i=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter Second number");
j=Convert.ToInt32(Console.ReadLine());
k=i+j;
return k;
}
}

·        File  Save in Strong Key pleace Let File Name IS shar.cs
·        Third .cs File Convert Into .Dll Fill
     Syntax Is:
                  C:\ csc  /t:library shar.cs


·  Fourth Mapping the .Dll file in Cache
   Syntax Is :
                   C:\gacutil  /I shar.dll
·        Fifth create an Other .cs File

using System;
public class a
public static void Main()
{
amit a1=new amit();
Console.WriteLine(a1.show());
Console.WriteLine(a1.add());
}
}

·  File Save  Any Location Let File Name Is      shar1.cs And Save In D:\\

· Compile The shar1.css And Take The Shar.Dll File Reference
  Syntax is:
                    D:\ csc /r  c:\\shar.dll shar1.cs

·  After the Compile Use Only file Name
   Syntax Is  :
                    D:\ Shar1