30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1008 ASP .<strong>NET</strong>, Web Forms and Web Controls Chapter 20<br />

17 Public Class Login<br />

18 Inherits System.Web.UI.Page<br />

19<br />

20 Protected WithEvents requiredPasswordValida<strong>to</strong>r As _<br />

21 RequiredFieldValida<strong>to</strong>r<br />

22<br />

23 Protected WithEvents invalidPasswordValida<strong>to</strong>r As _<br />

24 Cus<strong>to</strong>mValida<strong>to</strong>r<br />

25<br />

26 Protected WithEvents submitBut<strong>to</strong>n As But<strong>to</strong>n<br />

27 Protected WithEvents passwordTextBox As TextBox<br />

28 Protected WithEvents passwordLabel As Label<br />

29 Protected WithEvents nameList As DropDownList<br />

30 Protected WithEvents nameLabel As Label<br />

31 Protected WithEvents OleDbDataAdapter1 As OleDbDataAdapter<br />

32 Protected WithEvents OleDbSelectCommand1 As OleDbCommand<br />

33 Protected WithEvents OleDbInsertCommand1 As OleDbCommand<br />

34 Protected WithEvents OleDbUpdateCommand1 As OleDbCommand<br />

35 Protected WithEvents OleDbDeleteCommand1 As OleDbCommand<br />

36 Protected WithEvents OleDbConnection1 As OleDbConnection<br />

37 Protected WithEvents promptLabel As Label<br />

38 Protected dataReader As OleDbDataReader<br />

39<br />

40 ' <strong>Visual</strong> Studio .<strong>NET</strong> generated code<br />

41<br />

42 Private Sub Page_Init(ByVal sender As System.Object, _<br />

43 ByVal e As System.EventArgs) Handles MyBase.Init<br />

44<br />

45 InitializeComponent()<br />

46<br />

47 ' if page loads due <strong>to</strong> postback, process information<br />

48 ' otherwise, page is loading for first time, so<br />

49 ' do nothing<br />

50 If Not IsPostBack Then<br />

51<br />

52 ' open database and read data<br />

53 Try<br />

54 ' open database connection<br />

55 OleDbConnection1.Open()<br />

56<br />

57 ' execute query<br />

58 dataReader = _<br />

59 OleDbDataAdapter1.SelectCommand.ExecuteReader()<br />

60<br />

61 ' while we can read row from query result,<br />

62 ' add first item <strong>to</strong> drop-down list<br />

63 While (dataReader.Read())<br />

64 nameList.Items.Add(dataReader.GetString(0))<br />

65 End While<br />

66<br />

67 ' catch error if database cannot be opened<br />

68 Catch exception As OleDbException<br />

69 Response.Write("Unable <strong>to</strong> open database!")<br />

Fig. 20.39 Code-behind file for the login page for authors application (part 2 of 5).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!