COMMON All Day Lab 10/16/2007 Hands on VB.net and ASP.Net for iseries Developers

Size: px
Start display at page:

Download "COMMON All Day Lab 10/16/2007 Hands on VB.net and ASP.Net for iseries Developers"

Transcription

1 COMMON All Day Lab 10/16/2007 Hands on VB.net and ASP.Net for iseries Developers Presented by: Richard Schoen Bruce Collins Presentor Information Richard Schoen President of RJS Software Systems, Inc. Has developed software for over 23 years Started out on the System 34/36 in mid 1980 s Has been through the pain of learning web dev. Knows RPG,CL,VB,C,C#,Java,JSP,ASP Develops iseries, Windows and Linux software software for a living Cares about iseries Developers future Company provides.net Training/Consulting 1

2 Presentor Information Bruce Collins Decades of AS/400 iseries Development COMMON Board Member Proficient in C# and ASP.Net Agenda PC Development Environments Available Today Why Microsoft.Net Technology? Introduction to the.net Environment Why use VB vs C#? Prerequisite software to get started with the iseries and.net Introduction to Visual Studio 2005 Environment 2

3 Agenda Connecting to the iseries from.net Using ODBC, OLEDB or ASP.Net database driver? SQL Data Access 101 Build an iseries Database Connection Tester Application Build a Subfile-Style DataGrid Inquiry Application Agenda Submitting iseries Remote Commands via OLEDB Build a Remote Command Caller Directly Calling RPG or CL programs via OLEDB with Parameters Build a Program Call Sample What are program call stored procedures? Why use stored procedures? 3

4 Agenda Registering a Program Based Stored Procedure with the iseries Calling an RPG or CL program as a stored procedure with parameters Build a Program Call Sample Called as Stored Procedure Sample General iseries Query Utility What we didn't cover today? PC Development Environments Today Java/JSP/Websphere/Eclipse/WDSC Microsoft Visual Studio (ASP.NET/VB.Net/C#) RPG/Cobol/CGI/RPG Smart Pages PHP/Zend Core Ruby on Rails Several other open source variants Several tool vendors as well Differing opinions on which is best 4

5 Why Microsoft.Net Technology? New CFO Wants GUI Applications Younger job applicants know.net Needing to Write PC Applications Can get started quickly Can get started for FREE Update your skillset Introduction to the.net Environment.Net released in 2002 as Microsofts Response to Java Was second to market, but capitalized on strengths of Java Virtual Machine Met and exceeded Java functionality in Windows environment Capitalized and enhanced existing C++ and VB developer needs Got rid of DLL hell. All application files can live in one directory Easy to learn Works with iseries and other databases 5

6 Why use VB vs C#? English-like syntax No curly braces Easier to teach Usable in other MS Products such as: MS Word, Excel, Access, etc C## and VB can both be used if desired.net concepts apply to both C## and VB.Net Prerequisite software to get started with the iseries and.net PC with 512megs or above iseries Access ODBC Driver iseries Access OLEDB Driver iseries Access ADO.Net Driver Database drivers install as part of iseries Access setup Download FREE VB 2005 Express and Web Developer Edition or Purchase Visual Studio 2005 Recommended OS/400 Level V5R1 and above Visual Studio Express Download Site 6

7 Introduction to Visual Studio 2005 Environment Start the environment Discover the Toolbox Discover Project Types Discover Solution Explorer Discover the Error List Discover the ToDo-List Introduction to Visual Studio 2005 Environment Most important controls to learn Label fixed text Text box data entry field Button execute/run an action Menu execute/run an action via pulldown menu DataGridView Subfile for VB.Net Focus on these until you get comfortable 7

8 Connecting to the iseries from.net iseries Data can be accessed via any of the following CA/400 database drivers ODBC driver OLEDB driver ADO.Net driver Why are there 3 drivers? Evolution Using ODBC, OLEDB or ASP.Net database driver? ODBC driver is oldest method of access OLEDB driver is next generation ADO.Net driver is managed driver For our class we will be using the OLEDB driver OLEDB has ability to access iseries database or programs very easily ODBC, OLEDB and ADO.Net are relatively interchangeable because of.net data adapters Connection Code is almost identical for All 3 Once you know these, you can connect to other databases such as MySQL, SQL Server, etc.. 8

9 SQL Data Access 101 SELECT records SELECT statement used to select a group of records for us to view. Same as using Query/400 or other iseries query tools Records can be easily processed once selected Records can be quickly bound to a data grid for display. (Instant subfile) SQL Data Access 101 SELECT a group of records Sample SELECT statement SELECT * FROM QIWS.QCUSTCDT WHERE CUSNUM = * selects all fields FROM determines the iseries table name. WHERE Which record(s) are we reading? Library.File qualified naming convention 9

10 SQL Data Access 101 INSERT a new record Sample INSERT statement INSERT INTO QIWS.QCUSTCDT(LSTNAM, INIT,CDTBAL) VALUES( James, Johnson,5000) INTO determines the iseries table name Each individual field name being added Omitted fields are set to blanks or null VALUES The data field values String values always need to be surrounded by single quotes. Numeric values don t Fields separated by commas SQL Data Access 101 UPDATE existing record(s) Sample UPDATE statement UPDATE QIWS.QCUSTCDT SET CDTBAL = WHERE CUSNUM = Specify table name right after UPDATE. SET tells the UPDATE which fields to change. One or more field values can be specified Omitted fields are not touched WHERE Which record(s) are we updating? Note: Must use unique WHERE criteria if you are updating a specific record 10

11 SQL Data Access 101 DELETE existing record(s) Sample UPDATE statement DELETE FROM QIWS.QCUSTCDT WHERE CUSNUM = Specify table name right after FROM. No fields are specified. WHERE Which record(s) are we deleting? Note: Must use unique WHERE criteria if you are deleting a specific record WARNIING: If no WHERE clause, ALL records will be deleted. Use with care. Build an iseries Database Connection Tester Application Exercise the ODBC Driver Exercise the OLEDB Driver Exercise the ADO.Net Driver Data Grid is the.net equivalent of an iseries subfile Holds records much like a subfile does Has a visual component much like a subfile Makes writing visually appealing applications very easy Sample pgm: iseriesconnection1 11

12 Build a Subfile-Style DataGrid Inquiry Application Data Grid is the.net equivalent of an iseries subfile. Holds records much like a subfile does Has a visual component much like a subfile Makes writing visually appealing applications very easy This inquiry will use SQL SELECT to choose records to display Basis for your own subfile-like inquiry application Sample pgm: iseriessubfilesample1 Submitting iseries Remote Commands via OLEDB Create a graphical prompt screen for submitting batch jobs or running iseries commands Create a Windows prompt screen for submitting reports to batch Send messages to iseries system operator (QSYSOPR) 12

13 Build a Remote Command Caller Create remote command string to pass to OS/400 command call Use OLEDB connection to submit remote command Display errors if any occur Sample pgm: iseriescommandcall1 Directly Calling RPG or CL programs via OLEDB with Parameters OLEDB has direct call functionality Don t have to register iseries program as stored procedure ADO.Net does not have direct call functionality. Uses stored procedures Create parameter list Set parameter values Call program Return values to caller 13

14 Build a Program Call Sample Create parameters for program call Use OLEDB connection to call the program Return the parameters from program call Display errors if any occur General rule: Use OleDb.OleDbType.Char for character field parameters Use OleDb.OleDbType.Decimal for signed or packed numeric parameters Sample pgm: iseriesprogramcall1 What are program call stored procedures? A way to call an iseries program with parameters and return the parameter values via the SQL command mechanism Can also return database recordsets based on RPG or COBOL business program logic Allows business logic to be created in an RPG, CL or COBOL program RPG or COBOL business logic can be easily reused by PC, iseries or Web applications 14

15 Why use stored procedures? Store business logic in a single place Allow PC, iseries and Web applications to share the same business layer. Registering a Program Based Stored Procedure with the iseries You must register any program call stored procedure before use Program must exist on iseries OLEDB and ADO.Net support stored procedures All parameters are known by the iseries system after registration 15

16 Registering a Program Based Stored Procedure with the iseries Use STRSQL or Operations Navigator to create stored proc interactively Can only be registered once on system Create stored procedure CREATE PROCEDURE RJSDOTNET/TESTCL1SP (INOUT RTNMSG CHARACTER(50), INOUT AMOUNT DECIMAL(15,2)) RESULT SETS 0 EXTERNAL NAME RJSDOTNET/TESTCL1 LANGUAGE CL PARAMETER STYLE GENERAL Registering a Program Based Stored Procedure with the iseries Language parameter values C, CL, COBOL, COBOLLE, FORTRAN, PLI, RPG, RPGLE, JAVA, REXX RESULT SETS 0 means that only the parameters are returned. No recordset is returned. Remove stored procedure from STRSQL DROP PROCEDURE RJSDOTNET/TESTCL1SP 16

17 Calling an RPG or CL program as a stored procedure with parameters Similar to direct program call Stored procedure must be registered Create parameter list Set parameter values Call program as stored procedure Return values to caller Build a Program Call Sample Called as Stored Procedure Create parameters for program call Use OLEDB connection to call the program Return the parameters from program call Display errors if any occur Sample pgm: iseriesprogramcallsp1 17

18 Sample General iseries Query Utility Sample query program Semi-complete application Runs any SQL SELECT query Exports data to Excel XML format Office Open XML Format Sample pgm: iseriessqlquery1 ASP.Net Web Subfile Inquiry Data Grid is the.net equivalent of an iseries subfile. Holds records much like a subfile does Has a visual component much like a subfile Makes writing visually appealing applications very easy This inquiry will use SQL SELECT to choose records to display Basis for your own subfile-like inquiry application 18

19 What we didn t cover today? SQL stored procedures and returning recordsets Program call stored procedures and returning recordsets Creating a CRUD table maintenance application Creating a re-usable code module or Class to store shared business logic Materials and samples will be updated to cover above topics Sample Download Site VB Code & Library Need Formalized.Net Training? RJS provides formal.net training classes for VB.Net and ASP.Net RJS provides customized.net training classes.net Training Contact information: Derek Nordaune derek@rjssoftware.com Phn: 888-RJSSOFT -or

20 Register for.net Online Forum Site FREE benefit for today s class members RJS is going to be hosting an online forum site for iseries.net Developers Developers can ask.net and iseries.net related questions Additional code samples will be published on forum site Send contact information for login ID to: Richard Schoen richard@rjssoftware.com COMMON Feedback on.net for iseries Please provide feedback to COMMON on effectiveness of these labs Fill out your evaluation forms Was this lab relevent to your needs as a developer? What could we do to improve this lab class? Provide direct feedback to Richard and Bruce: Richard Schoen richard@rjssoftware.com Bruce Collins bruce.collins@aaacooper.com 20

21 COMMON All Day Lab 10/16/2007 Hands on VB.net and ASP.Net for iseries Developers Presented by: Richard Schoen Bruce Collins 21