Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ASP .NET Database Programming Weekend Crash Course - J. Butler, T. Caudill.pdf
Скачиваний:
31
Добавлен:
24.05.2014
Размер:
3.32 Mб
Скачать

Coding Differences in ASP and ASP.NET

363

Case Statements

How you did it with VBScript in ASP

Select Case sStockSymbol case “MSFT”

Response.Write(“Buy”)

case “ORCL” Response.Write(“Sell”)

case else Response.Write(“Hold”)

End Select

How you do it with VB .NET in ASP.NET

Select (sStockSymbol) case “MSFT” :

Response.Write(“Buy”)

case “ORCL” : Response.Write(“Sell”)

case else : Response.Write(“Hold”)

End Select

How you do it with C# in ASP.NET

switch (sStockSymbol) { case “MSFT” :

Response.Write(“Buy”);

break;

case “ORCL” : Response.Write(“Sell”); break;

default : Response.Write(“Hold”); break;

}

364

Appendix D

For Loops

How you did it with VBScript in ASP

Dim i

For i = 0 To 10

Response.Write “NewValue “ & i

Next

How you do it with VB .NET in ASP.NET

Dim i As Integer

For i = 0 To 10

Response.Write(“NewValue “ & i.ToString())

Next

How you do it with C# in ASP.NET

for (int i=0; i < 10; i++) { Response.Write(“New Value” + i.ToString());

}

While Loops

How you did it with VBScript in ASP

Dim i i = 0

Do While i < 1 Response.Write(i) i = i + 1

Loop

How you do it with VB .NET in ASP.NET

Dim i As Integer = 0

Do While i < 10 Response.Write(i.ToString()) i = i + 1

Loop

Coding Differences in ASP and ASP.NET

365

How you do it with C# in ASP.NET

int i = 0;

while (i < 10) { Response.Write(i.ToString()); i++;

}

String Concatenation

How you did it with VBScript in ASP

Dim s1, s2 s2 = “hello”

s2 = s2 & “ world”

s1 = s2 & “ !!!”

How you do it with VB .NET in ASP.NET

Dim s1, s2 As String s2 = “hello”

s2 &= “ world”

s1 = s2 & “ !!!”

How you do it with C# in ASP.NET

string s1;

string s2 = “hello”; s2 += “ world”;

s1 = s2 + “ !!!”;

Error Handling

How you did it with VBScript in ASP

Function WriteFile()

On Error Resume Next ‘Do Something ‘Raise a Fake Error Err.Raise(1000)

if Err.Number=0 Then WriteFile=”No Errors”

Else

WriteFile= Err.Number & “ was raised.” End If

End Function

366

Appendix D

How you do it with VB .NET in ASP.NET

Function WriteFile()

Try

‘Do Something

‘Raise a Fake Error

Err.Raise(1000)

Catch

Return “Error Number “ & Err.Number &” was raised.”

End Try

End Function

How you do it with C# in ASP.NET

public static string WriteFile(){ try{

/* Do Something to Raise Error */

throw new Exception(“1000”);

}

catch(Exception e){

return(“Error Number “ + e.Message + “ was raised”);

}

}

Conversion of Variable Types

How you did it with VBScript in ASP

Dim i

Dim s

Dim d

i = 3

s = CStr(i) d = CDbl(s)

How you do it with VB .NET in ASP.NET

Dim i As Integer

Dim s As String

Dim d As Double

i = 3

s = i.ToString() d = CDbl(s)

How you do it with C# in ASP.NET

int i = 10;

string s = i.ToString(); double d = double.Parse(s);

Get Up to Speed

in a Weekend!

Flash5 Weekend Crash

Red Hat® Linux® 7 Weekend

Course

Crash Course

by Shamms Mortier

by Naba Barkakati

408 pages

432 pages

ISBN 0-7645-3546-3

Red Hat Linux 7 on 3 CDs

 

ISBN 0-7645-4741-0

Visual Basic® 6 Weekend

Dreamweaver® 4 Weekend

Crash Course

Crash Course

by Richard Mansfield

by Wendy Peck

408 pages

408 pages

ISBN 0-7645-4679-1

ISBN 0-7645-3575-7

Also available:

Access® 2000 Programming Weekend Crash Course

by Cary N. Prague, Jennifer Reardon, Lawrence S. Kasevich, Diana Reid, and Phuc Phan 600 pages ISBN 0-7645-4688-0

Active Server Pages 3 Weekend Crash Courseby Eric Smith 450 pages ISBN 0-7645-4756-9

C++ Weekend Crash Course

by Stephen R. Davis 552 pages ISBN 0-7645-4689-9

C# Weekend Crash Course(Available July 2001) by Stephen R. Davis 432 pages ISBN 0-7645-4789-5

HTML 4.01 Weekend Crash Courseby Greg Perry 480 pages ISBN 0-7645-4746-1

Java2 Weekend Crash Course

by Julio Sanchez and Maria Canton 432 pages ISBN 0-7645-4768-2

JavaScript Weekend Crash Course

by Steven Disbrow 408 pages ISBN 0-7645-4804-2

JSP Weekend Crash Course

by Andrew Utter and Geremy Kawaller 408 pages ISBN 0-7645-4796-8

Linux® Weekend Crash Course

by Terry Collins and Naba Barkakati 450 pages ISBN 0-7645-3593-5

Each book comes with a CD-ROM and features 30 fast, focused lessons that will have you up and running in only 15 hours.

Available wherever books are sold,

or go to: www.hungryminds.com

© 2001 Hungry Minds, Inc. All rights reserved. Hungry Minds, the Hungry Minds logo and Weekend Crash Course are trademarks or registered trademarks of Hungry Minds. All other trademarks are the property of their respective owner.