How to access the multi-member phiscal file of iseries through. Net-two methods: alias ovrdbf
Source: Internet
Author: User
Using an alias to access a multi-member File
To use an alias to access a member other than the first member of a file, first create
Alias, and then use that alias instead of the file name. Example 4-97 shows how to create
An alias to the second member of file myfile, then use that alias to reference the member.
Example 4-97 accessing a multi-member file using an alias
Idb2command cmd = new idb2command ("create alias myschema. filembr2
Myschema. myfile (member2) ", CN );
Cmd. executenonquery ();
// Now access the second member using the alias we just created
Cmd. commandtext = "select * From myschema. filembr2 ";
Idb2datareader DR = cmd. executereader ();
// Etc.
Using ovrdbf to access a multi-member File
You can use the ovrdbf command to temporarily override a multiple-member database file
As shown in Example 4-98. Using the callpgm example we create in "a general method
Invoking qcmdexc "on page 120, we override the file so that SQL will reference member2
Instead of the first Member in the file. After calling ovrdbf as we show in this example, SQL
Statements that reference the file myschema. myfile use the second Member, member2.
Example 4-98 using ovrdbf to access the second member of a multi-member File
Rc = callpgm ("ovrdbf file (myfile) tofile (myschema/myfile) MBR (member2) ovrscope (* job )",
CN );
// Now a select * From myschema. myfile will access member member2
Cmd. commandtext = "select * From myschema. myfile ";
Idb2datareader DR = cmd. executereader ();
// Etc.
Processing Cl commands that produce an OUTFILE
Using Cl commands provide an option to store the command output into an OUTFILE, which is
Database file that can be queried using a SQL SELECT statement, just like any other table. In
Example 4-99 on page 124, we execute a dspusrprf command through qcmdexc using
The callpgm method we created in Example 4-94 on page 121. After running this command,
We execute a SELECT statement to select all of the user profiles from the table (OUTFILE) that
Was created by dspusrprf. We use a datareader to read information from the table.
124 integrating DB2 Universal Database for iseries with Microsoft ADO. net
Example 4-99 processing a CL command that produces an OUTFILE
// Create and open a connection to the iseries.
Idb2connection Cn = new
Idb2connection ("datasource = myiseries; defaultcollection = sampledb ;");
CN. open ();
// Call the callpgm method to execute the dspusrprf command
// And tell it to put the output into an OUTFILE.
Bool success = callpgm ("dspusrprf usrprf (* All) output (* OUTFILE)
OUTFILE (sampledb/usrprfinfo) ", CN );
// If the call succeeded, open a datareader to read a list
// All the user profiles in the OUTFILE.
If (success = true)
{
Idb2command cmd = new idb2command ("select upuprf from usrprfinfo", CN );
Idb2datareader DR = cmd. executereader ();
While (dr. Read ())
{
Console. writeline ("user profile:" + dr. getstring (0 ));
}
// Close the datareader since we're re done using it.
Dr. Close ();
// Dispose the command since we no longer need it.
Cmd. Dispose ();
}
// Close the connection since we're re done using it.
CN. Close ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.