Sunteți pe pagina 1din 0

!"# $%&(*,#. /1213. 42,"5#.

Reserved Words
abstract decimal float namespace return typeof
as default for new sbyte uint
base delegate foreach null sealed ulong
bool do goto object short unchecked
break double if operator sizeof unsafe
byte else implicit out stackalloc ushort
case enum in override static using
catch event int params struct virtual
char explicit interface private switch volatile
checked extern internal protected this void
class false is public throw while
const finally lock readonly true
continue fixed long ref try

79.: 42;2/<#. >.&;? C# Built-in Data Types
Data Type Range brief
byte 0 .. 255 byt
sbyte -128 .. 127 sbt
short -32,768 .. 32,767 srt
ushort 0 .. 65,535 urt
int -2,147,483,648 .. 2,147,483,647 int
uint 0 .. 4,294,967,295 unt
long -9,223,372,036,854,775,808 .. 9,223,372,036,854,775,807 lng
ulong 0 .. 18,446,744,073,709,551,615 ung
float -3.402823e38 .. 3.402823e38 flt
double -1.79769313486232e308 .. 1.79769313486232e308 dbl
decimal -79228162514264337593543950335..
79228162514264337593543950335
dcm
char A Unicode character. chr
string A string of Unicode characters. str
bool True or False. bln
object An object. obj

string strName; // warning The variable declared but never used
double dblAge = 20.5;
int intA, intB;
int intC = 10, intD, intF = 20;
const string conMsg = "Hello";
const bool bolA = true, bolB = false;
string strA; const string conA = "Text";

42@/"AB#. Comments
// this a single line comment.

PDF created with pdfFactory trial version www.pdffactory.com
/* this a
Multiline comment
That ends here. */

4.D/<AB#. Expression













protected void Page_Load(object sender, EventArgs e)
{
const double conPi = 3.14159;
double dblRadius, dblArea;
dblRadius = 1;
dblArea = conPi * dblRadius * dblRadius;
Response.Write("Area = " + dblArea);
}

F'? : /=2G*#. 7-.&A#. Arithmetic Operators
Operator Description Usage
Example
Value/Result
+ Addition !#%& 5 + 3 8
- Subtraction '(*%& 5 - 3 2
Unary Negation ,%./%& -2 -2
* Multiplication -(1%& 5 * 3 15
/ Division 3!/4%& 15 / 3 5
% Modulus 35759%& 3!/4%& ;<.= 17 % 3 2
+ +




Increment 1 and then return value
)&>4!= @AB C?.8D%& 1 3!7< F.$)G HJ ) prefix (
int x=5 , y=3;
y = ++ x;
y = 6
x = 6
Return value and then increment 1
3!74%& C?.8E HJ @AB 3!74%& F.$)G 1 ) postfix (
int x=5 , y=3;
y = x ++;
y = 5
x = 6
- - Decrement 1 and then return value
3!74%& K.4LG 1 3!74%& F.$)G HJ ) prefix (
int x=5 , y=3 ;
y = --x ;
y=4
x=4
Return value and then decrement 1
K.4LG HJ @AB 3!74%& F.$)G 1 ) postfix (
int x=5 , y=3;
y = x--;
y=5
x=4
PDF created with pdfFactory trial version www.pdffactory.com
2/;2H : I/KMB#. 7-.&N Assignment Operators
Operator Description Example Result
= (7MN!%& AB (7PQN%& RO.L SUV8 (/8W& (7MN!%& X!8W& int x= 5+3; x=8
+= X!8W& (7PQN%& AB (7MN!%& 3!7< )&>4!= (/8W& (7MN!%& 3!7< >8DO
KZ9[%& " .18B \!QOA
int x=2;
x += 3;
x=5
-= (7PQN%& AB (7MN!%& 3!7< )&>4!= (/8W& (7MN!%& 3!7< X" ^4[O
X!8W&
int x=2;
x -= 5;
x=-3
*= X!8W& (7PQN%& AB (7MN!%& 3!7< ;_ (/8W& (7MN!%& 3!7< -(1O Int x=2;
x *= 5;
x=10
/= X!8W& (7PQN%& AB (7MN!%& 3!7< ;`a (/8W& (7MN!%& 3!7< 3!/< HN8 int x=10;
x /=2 ;
x=5
%= HN8 X!8W& (7PQN%& AB (7MN!%& 3!7< ;`a (/8W& (7MN!%& 3!7< 3!/<
35759%& 3!/4%& X" ;4PO ." (/8W& (7MN!`% 18 HJ .
int x=11;
x%=2;
x=1

Write it Don't write it
variable *= number; variable = variable * number;
variable /= number; variable = variable / number;
variable %= number; variable = variable % number;
variable += number; variable = variable + number;
variable -= number; variable = variable - number;

2O#2H : J&KP#. Q-: 7-2N Concatenation String Operator
string x ="Welcome to", y="C# programming!";
x= x+y;
Response.Write(x);
! Welcome toC# programming
string x ="Welcome to", y="C# programming!";
x= x + " " + y;
Response.Write(x);

string x = "Welcome to", y = "C# programming!";
x += " ";
x += y;
Response.Write(x);
! Welcome to C# programming

2A=.E : RHSO#. RTDV#. D/<AB#. 7-2N Conditional Expression Ternary
(Condition) ? value1 if true : value2 if false

protected void Page_Load(object sender, EventArgs e)
{
intFirst = 10, intSecond = 20, intLarge;
intLarge = (intFirst > intSecond) ? intFirst : intSecond;
Response.Write("<h2>Large Number Is:" + intLarge + "</h2>");
PDF created with pdfFactory trial version www.pdffactory.com
}

Large Number Is:20
2G-29 : ;E2@,#. 7-.&N Comparison (Relational) Operators
Operator Description Usage Example Value/Result
== Equal int x= 5, y= 6 ,z;
z = (x == y)? x :
y;
z = 6
!= Not Equal int x= 5, y= 6 ,z;
z = (x != y)? x : y;
z =5
< Less Than int x= 5, y= 6 ,z;
z = (x < y)? x : y;
z =5
<= Less Than or Equal int x= 5, y= 6 ,z;
z = (x <= y)? x :
y;
z =5
> Greater Than int x= 5, y= 6 ,z;
z = (x > y)? x : y;
z =6
>= Greater Than or Equal int x= 5, y= 5 ,z;
z = (x >= y)? x :
y;
z =5

21:21 : /@XP,#. 7-.&A#. Logical Operator
Operato
r
Description Usage Example Result
&& .b.[Q"A ) And ( YZc8 YB ;[QOA
.!eN!7< X7%Z!Q!%& true
int x = 5, y = 5, z ;
z = ((x == y) && (x != 5)) ? x : 10
;
z = 10
|| .b.[Q"A ) Or ( f>6G YZc8 YB ;[QOA
gN!7< X7%Z!Q!%& true \<W& ;`a
int x = 5, y = 5, z ;
z = ((x == y) || (x != 5)) ? x : 10 ;
z =5
! .b.[Q"A ) Not ( >76A \".Q" SUVOA
Y.h YG g7i[OA true g`Q#O false
Y.h YGA false g`Q#O true
int x = 5, y = 5, z ;
z = ( !(x == y) || (x != 5)) ? x : 10 ;
z =10

2A=21 : Y<#. 4.Z+' [&BG- R"N (#2A,#. 7-.&N Bit Manipulation
Category Operator Description
Bit Shift >> Shift right
<< Shift left
Bitwise Logical & Integer bitwise AND, boolean logical AND
| Integer bitwise OR, boolean logical OR
^ Integer bitwise XOR, boolean logical XOR
Bitwise Assignment >>= , <<= , &= , |= , ^=
Unary Bitwise ~ One's complement (unary NOT) j negative

2P-2H : [D9? 7-.&N Other Operators
Operator Description Usage Example Result
PDF created with pdfFactory trial version www.pdffactory.com
x is type 7-2A#. \)D0 is ,/@#.
true ]2^ ]_ x `-
E&^a,#. >&P#. ce;
type \)DC' false Rf
4F2*#. Rg2= .
int x=5; string y;
y= (x is short) ? "yes" : "no";
y = no
typeof(x) 42;2/<#. >&; \)DC
data type hh= J2M#.
x
int x = 5;
Type z = typeof(x)
type of
variable z is
int
new
Type(...)
7-2N `i25#. j2V;_
object li2P#.'
delegate
Random intRnd = new Random();
intRnd.Next(1,7);
Print random
number
between 1:6
new
Type[...]
42f&eK,#. j2V;_ 7-2N
Arrays
int[] intArr=new int[4];
intArr[0] = 10; intArr[1] = 20;
Response.Write(intArr[1]);

20
x as Type n/g 7^ \)DC x `-
>&P#. type ]_' :Z*,#.
ce; `- n/@#. `5C n#
,/@#. \)D0 >&P#. null
object[] objArr= new object[3];
objArr[0]=123; objArr[1]=false;
objArr[2]="hello";
string s1 = objArr[1] as string;
string s2 = objArr[2] as string;
s1=null
s2="hello"
default(T)

/p.DBfF. ,/@#. \)D0
:Z*,#. >&P"# Type
Response.Write(default(string));
Response.Write(default(int));
Response.Write(default(bool));
null
0
False
X ?? y ,/g Y;2^ .b_ x /#29
null ,/g a9q/f y FZ=
a9q0 r#b D/t' 2uPN
,/g x

Response.Write("yes"?? "ok");
Response.Write(null ?? "ok");

Yes
ok

2A12C : v0DK#. 70&*B#. 7-2N Explicit Convert Operator
protected void Page_Load(object sender, EventArgs e)
{
double x = 250.6 ; int y;
y = (int)x;
Response.Write("<h2> Y = " + y + "</h2>"); // Printed Y = 250
}
0&#'? 7-.&A#. a/ePC Operators Precedence
Category Operators
Primary ( ) , x++, x--, new, typeof 1
Unary +, -, !, ++x, --x 2
Arithmetic Multiplicative *, /, % 3
Arithmetic Additive +, - 4
Shift <<, >> 5
Relational and type testing <, >, <=, >=, is 6
Equality ==, != 7
precedence Logical, in order of &, ^, | 8
precedence Conditional, in order of &&, ||, ?: 9
Assignment =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>= 10


PDF created with pdfFactory trial version www.pdffactory.com
42;2/<#. >.&;? `/= 70&*B#. Conversion Between Data Types
F'? : RP,w#. 70&*B#. Implicit Conversion
int intNum =25 ; double dblNum;
dblNum = intNum; //implicitly box the int value

int intNum =25 ; double dblNum=25.98537 ;
intNum = dblNum ; // Error : Cannot implicitly convert

From To
sbyte short, int, long, float, double, or decimal
byte short, ushort, int, uint, long, ulong, float, double, or decimal
short int, long, float, double, or decimal
ushort int, uint, long, ulong, float, double, or decimal
int long, float, double, or decimal
uint long, ulong, float, double, or decimal
long float, double, or decimal
char ushort, int, uint, long, ulong, float, double, or decimal
float double
ulong float, double, or decimal
bool No possible implicit conversions to other simple types.
decimal No possible implicit conversions to other simple types.
double No possible implicit conversions to other simple types.

2/;2H : v0DK#. 70&*B#. Explicit Conversion
int intNum; double dblNum=25.98537 ;
intNum =(int) dblNum ;// explicitly box the double value

int intNum; double dblNum=25.98537 ;
intNum = Convert.ToInt32 (dblNum); // explicitly box the double value
Convert.
( ToBoolean, ToByte, ToChar, ToDateTime, ToDecimal, ToDouble, ToInt16, ToInt32,
ToInt64, ToSByte, ToSingle, ToString, ToUInt16, ToUInt32, ToUInt64 )

/(-D<#. 7,(#. Statements Programming
Category Description
Declaration statements Used to declare local variables and constants.
Expression statements Used to evaluate expression.
Selection statements Used to select one of a number of possible statements for
execution based on the value of some expression. In this
group are the (if and switch) statements.
Iteration statements Used to repeatedly execute an embedded statement. In this
group are the (while, do, for, and foreach) statements.
PDF created with pdfFactory trial version www.pdffactory.com
Jump statements Used to transfer control. In this group are the break,
continue, goto, throw, return, and yield statements.
Exception Handling
statements
The try...catch statement is used to catch exceptions that
occur during execution of a block, and the try...finally
statement is used to specify finalization code that is always
executed, whether an exception occurred or not.
checked and unchecked
statements
Used to control the overflow checking context for integral-
type arithmetic operations and conversions.
using statement Used to obtain a resource, execute a statement, and then
dispose of that resource.

1 - x0DAB#. ",) Declaration Statement
Syntax of Declaration Statement







var i = 5;
var s = "Hello";
var d = 1.0;
var numbers = new int[] {1, 2, 3};

var x; // Error, no initializer to infer type from
var y = {1, 2, 3}; // Error, array initializer not permitted
var z = null; // Error, null does not have a type
var u=5 , m=3 ; // Error, cannot have multiple declarators
var v = v++; // Error, initializer cannot refer to variable itself

2 - E2<A#. ",) 4. 0D<(#. ) #. D/<AB ( Expression Statement
Syntax of Expression Statements











1-Local-variable-declaration:
a) Local-variable-type Identifier
b) Local-variable-type Identifier = local-variable-initializer
c) var Identifier = local-variable-initializer
2- local-constant-declaration:
const type identifier = constant-expression
expression-statement:
invocation-expression
object-creation-expression
assignment
post-increment-expression
post-decrement-expression
pre-increment-expression
pre-decrement-expression
PDF created with pdfFactory trial version www.pdffactory.com
3 - ",) if Statement
Syntax of If Statement










protected void Page_Load(object sender, EventArgs e)
{
if (DateTime.Now. Hour< 12)
Response.Write("<h2>Good morning</h2>");
Response.Write("<h2>" + DateTime.Now + "</h2>");
}







protected void Page_Load(object sender, EventArgs e)
{
if (DateTime.Now.Hour < 12)
{ Response.Write("<h2>Good morning</h2>");
Response.Write("<h2>" + DateTime.Now + "</h2>"); }
}










if-statement:
1- if ( boolean-expression ) embedded-statement
2- if ( boolean-expression ) embedded-statement
else embedded-statement
PDF created with pdfFactory trial version www.pdffactory.com
protected void Page_Load(object sender, EventArgs e)
{
if (DateTime.Now.Second < 12)
{ Response.Write("<h2>Good morning</h2>");
Response.Write("<h2>" + DateTime.Now + "</h2>");
}
else
Response.Write("<h2>Good evening</h2>"); }








protected void Page_Load(object sender, EventArgs e)
{
Random rnd = new Random();
string strLGrade = "" ;
int intGrade = rnd.Next(100); //random number between 0 and 100
Response.Write("<h2>your grade is: " + intGrade + "</h2>");
if (intGrade >= 90)
{
strLGrade = "A";
Response.Write("<p>You got A! Congratulations.</p>");
}
else
if (intGrade >= 80)
strLGrade = "B";
else if (intGrade >= 70)
strLGrade = "C";
else if (intGrade >= 60)
strLGrade = "D";
else if (intGrade < 60)
{
strLGrade = "F";
Response.Write("<p>You failed I'm sorry.</p>");
}
Response.Write("Your Letter Grade: " + strLGrade);
}

4 - E2/B9F. ",)' m'Du#. ",)' ].&PA#. ",)' R#_ 7@B;. ",)
goto, Labeled, break and switch statements
Syntax:

PDF created with pdfFactory trial version www.pdffactory.com








protected void Page_Load(object sender, EventArgs e)
{ int x=1;
next:
Response.Write(x +"<br/>");
x++;
if (x < 5) goto next;
}

",) switch Statement
Syntax of switch Statement













protected void Page_Load(object sender, EventArgs e)
{ switch(DateTime.Now.Month)
{ case 1: Response.Write("January"); break;
case 2: Response.Write("February"); break;
case 3: Response.Write("March"); break;
case 4: Response.Write("April"); break;
case 5: Response.Write("May"); break;
case 6: Response.Write("June"); break;
case 7: Response.Write("July"); break;
case 8: Response.Write("August"); break;
case 9: Response.Write("September"); break;
case 10: Response.Write("October"); break;
1- labeled-statement:
identifier : statement
2- goto-statement:
a) goto identifier ;
b) goto case constant-expression ;
c) goto default ;
3- break-statement:
break ;
switch-statement:
switch ( expression )
{
case constant-expression :
statement-list ;
break;
case

default :
statement-list ;
break;
PDF created with pdfFactory trial version www.pdffactory.com
case 11: Response.Write("November"); break;
default: Response.Write("December"); break;
} // end of switch
} //end page_load method

switch(strA)
{case "ok":
case "OK":
x=2*3; //code execute if strA="ok" or strA="OK"
break;
}

5 - ",) while Statement
Syntax of while Statement




protected void Page_Load(object sender, EventArgs e)
{ int intCounter = 1; //declare and initialize control variable
while (intCounter < 7)
{ Response.Write("<h2>Counter= "+ intCounter +"</h2>" );
intCounter ++; //increment control variable
} //end while
}









6 - ",) do Statement
Syntax of do Statement






while-statement:
while ( boolean-expression ) embedded-statement
do-statement:
do embedded-statement while ( boolean-expression ) ;
PDF created with pdfFactory trial version www.pdffactory.com
protected void Page_Load(object sender, EventArgs e)
{ int intCounter = 1; //declare and initialize control variable
do
{ Response.Write("<h2>Counter= "+ intCounter +"</h2>" );
intCounter ++; //increment control variable
} while (intCounter < 7);
}
7 - ",) for Statement
Syntax of for Statement





protected void Page_Load(object sender, EventArgs e)
{
for( int intCounter = 1; intCounter < 7; intCounter ++)
Response.Write("<h2>Counter= "+ intCounter +"</h2>" );
}
8 - ",) foreach Statement
Syntax of foreach Statement





protected void Page_Load(object sender, EventArgs e)
{
string[] strProducts = new string[5]
{ "CPU", "Monitor", "keyboard", "Speaker", "Printer" };
Response.Write("<ol>My Products :");
foreach (var strProduct in strProducts)
Response.Write("<li>" + strProduct + "</li>");
Response.Write("</ol>");
}








for-statement:
for ( for-initialize ; boolean-expression ; statement-expression-list
)
foreach-statement:
foreach ( local-variable-type identifier in expression )
embedded-statement
PDF created with pdfFactory trial version www.pdffactory.com
9 - ",) continue
Syntax of continue Statement




protected void Page_Load(object sender, EventArgs e)
{
for (int x = 1; x < 10; x++)
{
if (x % 2 == 1) continue;
Response.Write(x + "<br/>");
}
}

10 - ",) lock
Syntax of lock Statement




protected void Page_Load(object sender, EventArgs e)
{ decimal dcmBalance=3000;
decimal dcmAmount=500;
lock (this)
{ if (dcmAmount < dcmBalance)
{
dcmBalance -= dcmAmount; // safety to work with database
Response.Write("Current Balance =" + dcmBalance);
}//end if
}//end lock
}//end method

protected void Page_Load(object sender, EventArgs e)
{
using (System.IO.TextWriter w = System.IO.File.CreateText("c:\\FromWebSite.txt"))
{ w.WriteLine("Dr:");
w.WriteLine("Adel Sabour Ahmad");
} }





continue-statement:
continue ;
lock-statement:
lock ( expression ) embedded-statement
PDF created with pdfFactory trial version www.pdffactory.com
3. 42NDeC j2,1 Namespace






System.Data.OleDb.OleDbConnection

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
using (TextWriter w = File.CreateText("c:\\FromWebSite.txt"))
{ w.WriteLine("Mr:");
w.WriteLine("Adel Sabour");
}
using (TextReader r = new StreamReader("c:\\FromWebSite.txt"))
{ string strLine;
while((strLine=r.ReadLine()) != null )
Response.Write("<h2>"+ strLine +"</h2>");
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<body></body></html>

11 - 4.j2POB1F. (#2A- ",) Handling Exception Statements
Syntax of Handling Exception Statement












try-statement:
1- try block catch-clauses
2- try block finally-clause
3- try block catch-clauses finally-clause
try embedded-statement
catch (class-type identifier) embedded-statement
finally embedded-statement
PDF created with pdfFactory trial version www.pdffactory.com


Exception
o SystemException
ArithmeticException
DivideByZeroException
OverflowException

FormatException
ExternalException
DbException
o OleDbException
o OracleException
o SqlException
o

o SmtpException
o

protected void Page_Load(object sender, EventArgs e)
{ int intX = 0, intY;
try
{
intY = 215 / intX;
Response.Write("intY = " + intY);
}
catch (DivideByZeroException expZero)
{
Response.Write("<h4 style='color:red'>Exception: Divide By Zero</h3>");
}
catch (Exception exp)
{
Response.Write("<h4 style='color:red'>Exception: " + exp.Message + "</h3>");
}
finally
PDF created with pdfFactory trial version www.pdffactory.com
{
Response.Write("Execution of sensitive code is complete");
}
}






12 - I*e#. 7,) check and uncheck Statements
Syntax of check and uncheck Statements








int intY = int.MaxValue; // then intY=2147483647
int intX = intY+5;
Response.Write("intX =" + intX);
intX =-2147483644
int intY = int.MaxValue;
try
{ int intX = checked(intY + 5);
Response.Write("intX =" + intX); }
catch (OverflowException expOver)
{
Response.Write("<h4 style='color:red'>Exception: Arthimetic Overflow!</h4>");
}
catch(Exception exp)
{
Response.Write("<h4 style='color:red'>Exception:" + exp.Message + "</h4>");
}







checked-statement:
checked block
unchecked-statement:
unchecked block
PDF created with pdfFactory trial version www.pdffactory.com
13 - j2POB1. z2B;_ ",) throw Statement
Syntax of throw Statement





protected void Page_Load(object sender, EventArgs e)
{ Random rndMonth = new Random();
switch(rndMonth.Next(1,14) )
{ case 1: Response.Write("January"); break;
case 2: Response.Write("February"); break;
case 3: Response.Write("March"); break;
case 4: Response.Write("April"); break;
case 5: Response.Write("May"); break;
case 6: Response.Write("June"); break;
case 7: Response.Write("July"); break;
case 8: Response.Write("August"); break;
case 9: Response.Write("September"); break;
case 10: Response.Write("October"); break;
case 11: Response.Write("November"); break;
case 12: Response.Write("December"); break;
default: throw new ArgumentOutOfRangeException("Bad Month");
}
}







14 - ",) return
Syntax of return Statement





returntype methodname( parameterlist )
{
//method body statements
}

throw-statement:
throw expression(new System.Exception("Msg") ) ;
return-statement:
return expression ;
PDF created with pdfFactory trial version www.pdffactory.com
<script runat="server">
void randomNumbers()
{
Random rndNum = new Random();
Response.Write("<h3>Random Number :" + rndNum.Next() +"</h3>");
}
protected void Page_Load(object sender, EventArgs e)
{
randomNumbers();
randomNumbers();
randomNumbers();
}
</script>







<script runat="server">
int randomNumbers()
{
Random rndNum = new Random();
return rndNum.Next();
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<h2>First Random Number:" + randomNumbers() + "</h2>");
Response.Write("Second Random Number IS" + randomNumbers());
Response.Write("<br>Third Random Number=" + randomNumbers());
}
</script>







<script runat="server">
int randomNumbers(int Min,int Max)
{
Random rndNum = new Random();
return rndNum.Next(Min,Max+1);
PDF created with pdfFactory trial version www.pdffactory.com
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Random Number Between 5 and 8= " + randomNumbers(5,8) );
Response.Write("<br>Between 1000 and 1010=" + randomNumbers(1000,1010));
Response.Write("<br>Number Between 10 and 50=" + randomNumbers(10,50));
}
</script>






82(- 42e0DAB#. Scope of declarations
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
int intScript = 1, intx=2;
protected void Page_Load(object sender, EventArgs e)
{
int intMethod = 3;
if(intMethod ==3)
{
int intx=4,intIf=5;
Response.Write("<br/>From if Statement >> intx = " + intx);
Response.Write("<br/>From if Statement >>intMethod=" + intMethod);
Response.Write("<br/>From if Statement >>intScript=" + intScript);
Response.Write("<br/>From if Statement >>intif=" + intif);
}
// do'nt use intx here
Response.Write("<br/>From Method >>intMethod=" + intMethod);
Response.Write("<br/>From Method >>intScript=" + intScript);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<% int intPage = 5;
Response.Write("<br/>From Body >>intScript=" + intScript);
Response.Write("<br/>From Body >> intx = " + intx);
Response.Write("<br/>From Body >>intPage=" + intPage ); %>
</body>
</html>

PDF created with pdfFactory trial version www.pdffactory.com









Registration Service (2)

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Registration Form</title>
<style type="text/css">
.style1
{ width: 70%;
border-style: none;
border-width: 1px; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center" cellspacing="3" class="style1" dir="ltr">
<tr>
<td colspan="2"
style="font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size:
large; text-decoration: underline overline; background-image:
url('images/back2.GIF'); background-repeat: repeat-y">
Sign Up for Your New Account</td>
</tr>
<tr>
<td >
<asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Full Name :" />
</td>
<td>
<asp:TextBox ID="txtName" runat="server" Font-Bold="True"></asp:TextBox>
</td>
</tr>
<tr>
<td>
PDF created with pdfFactory trial version www.pdffactory.com
<asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Gender :" />
</td>
<td>
<asp:RadioButtonList ID="rblGender" runat="server" Font-Bold="True"
RepeatDirection="Horizontal" Width="168px">
<asp:ListItem Selected="True" Value="M">Male</asp:ListItem>
<asp:ListItem Value="F">Female</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Font-Bold="True" Text="Country :" />
</td>
<td>
<asp:DropDownList ID="ddlCountry" runat="server" Width="168px">
<asp:ListItem>Egypt</asp:ListItem>
<asp:ListItem>Oman</asp:ListItem>
<asp:ListItem>Kuwait</asp:ListItem>
<asp:ListItem>Sodan</asp:ListItem>
<asp:ListItem>Lebya</asp:ListItem>
<asp:ListItem>Bahreen</asp:ListItem>
<asp:ListItem>Qatar</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Font-Bold="True" Text="E-Mail :" />
</td>
<td>
<asp:TextBox ID="txtEmail" runat="server" Font-Bold="True"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Font-Bold="True"
Text="Security Question :"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtQuestion" runat="server"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Font-Bold="True" Text="Security Answer :" />
</td>
<td>
<asp:TextBox ID="txtAnswer" runat="server" Font-Bold="True"></asp:TextBox>
PDF created with pdfFactory trial version www.pdffactory.com
<br />
if you forget your password we will ask for the answer to your security Question
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Font-Bold="True" Text="User Name :" />
</td>
<td>
<asp:TextBox ID="txtUser" runat="server" Font-Bold="True"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" runat="server" Font-Bold="True" Text="Password :" />
</td>
<td>
<asp:TextBox ID="txtPass" runat="server" Font-Bold="True"
TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox ID="chbTerms" runat="server" Font-Bold="False"
Text="I agree to Al Salam Company &lt;a
href=&quot;terms.htm&quot;&gt;Terms of Service&lt;/a&gt;" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblMsg" runat="server" Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<td > &nbsp;</td>
<td>
<asp:Button ID="btnRegister" runat="server" Font-Bold="True"
Text="Create Account" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>






PDF created with pdfFactory trial version www.pdffactory.com
F'? : 42;2/<#. ZN.&@= 82KCF. `i2^ Connection Object

















<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void btnRegister_Click(object sender, EventArgs e)
{
// Code Here
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
<asp:Button ID="btnRegister" runat="server" Font-Bold="True"
Text="Create Account" onclick="btnRegister_Click" />

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




1 <%@ Page Language="C#" %>
2 <%@ Import Namespace="System.Data.SqlClient"%>
3 <script runat="server">
4 protected void btnRegister_Click(object sender, EventArgs e)
5 {
6 SqlConnection conn = new SqlConnection();
7 conn.ConnectionString ="Data Source=.\\SQLEXPRESS;"
8 +"AttachDbFilename=|DataDirectory|\\AlSalam.mdf;"
9 +"Integrated Security=True;User Instance=True";
PDF created with pdfFactory trial version www.pdffactory.com
10 conn.Open();
11 lblMsg.Text = "Connection Successful";
12 conn.Close();
13 }
14 </script>




2/;2H : `i2^ a/ePC 3. D-.' R"N 42;2/<#. ZN.&g Command Object














7,) `0&5C /e/^ SQL
















PDF created with pdfFactory trial version www.pdffactory.com
Registration






















1 <%@ Page Language="C#" %>
2 <%@ Import Namespace="System.Data.SqlClient"%>
3 <script runat="server">
4 protected void btnRegister_Click(object sender, EventArgs e)
5 {
6 string strInsert =
7 String.Format(
8 "Insert Into Member values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
9 txtName.Text, rblGender.SelectedValue, ddlCountry.SelectedValue,
10 txtEmail.Text, txtQuestion.Text, txtAnswer.Text, txtUser.Text, txtPass.Text);

11 string strConn = "Data Source=.\\SQLEXPRESS;"
12 + "AttachDbFilename=|DataDirectory|\\AlSalam.mdf;"
13 + "Integrated Security=True;User Instance=True";

14 SqlConnection conn = new SqlConnection();
15 SqlCommand cmdInsert = new SqlCommand();

PDF created with pdfFactory trial version www.pdffactory.com
16 conn.ConnectionString = strConn;
17 cmdInsert.Connection = conn;
18 cmdInsert.CommandText = strInsert;

19 if(chbTerms.Checked == false)
20 lblMsg.Text = "please check you agree to al salam company terms of services .";
21 else
22 { conn.Open();
23 cmdInsert.ExecuteNonQuery();
24 conn.Close();
25 lblMsg.Text = "your account has been successfully created."; }
26 }
27 </script>
28 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
29 <html></html>




1 <%@ Page Language="C#" %>
2 <%@ Import Namespace="System.Data.SqlClient"%>
3 <script runat="server">
4 protected void btnRegister_Click(object sender, EventArgs e)
5 {
6 string strInsert = String.Format(
7 "Insert Into Member values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
8 txtName.Text, rblGender.SelectedValue, ddlCountry.SelectedValue,
9 txtEmail.Text, txtQuestion.Text, txtAnswer.Text, txtUser.Text, txtPass.Text);

10 string strConn="Data Source=.\\SQLEXPRESS;"
11 + "AttachDbFilename=|DataDirectory|\\AlSalam.mdf;"
12 + "Integrated Security=True;User Instance=True";

13 SqlConnection conn = new SqlConnection();
14 SqlCommand cmdInsert = new SqlCommand();

15 conn.ConnectionString = strConn;
16 cmdInsert.Connection = conn;
17 cmdInsert.CommandText = strInsert;

18 if(chbTerms.Checked==false)
19 lblMsg.Text = "please check you agree to al salam company terms of services .";
20 else
21 { try
22 {
23 conn.Open();
24 cmdInsert.ExecuteNonQuery();
25 conn.Close();
PDF created with pdfFactory trial version www.pdffactory.com
26 lblMsg.Text = "your account has been successfully created.";
27 }
28 catch (SqlException expSql)
29 {
30 if (expSql.Number == 2627)
31 lblMsg.Text = "username already exist Please enter a different user name.";
32 else
33 lblMsg.Text = "Sorry!! Database Error";
34 }
35 catch
36 {
37 lblMsg.Text = "Your account was not created. Please try again.";
38 }
39 }
40 }
41 </script>
42 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
43 <html></html>




PDF created with pdfFactory trial version www.pdffactory.com

S-ar putea să vă placă și