Safemapping

xiaoxiao2021-03-06  63

Create Table Empinfo (Empno Number (4) Primary Key, Empname Varchar2 (20) Not Null, HiRedate Date, Salary Number (7, 2), JobDescription Clob, Bytecodes blob); ============ ======================= // c # // the folload example show to use the Safemapping Property to Fill The DatasetPublic static void buyafeMapping (String Connstr) {

// in this Select Statement, Empno, Hiredate and Salary Must Be // Preserved Using Safe Type Mapping.String Cmdstr = "SELECT EMPNO, Empname, HiRedate, Salary from Empinfo";

// Create the adapter with the selectcommand txt and the connection stringoracledataadapter Adapter = New OracleDataAdapter (cmdstr, connStr);

// Get the connection from the adapteroraclectConnection connection = adapter.selectCommand.connection;

// create the safe type mapping for the adapter // which can safely map column data to byte arrays, where // applicable. By executing the following statement, EMPNO, HIREDATE AND // SALARY columns will be mapped to byte [] adapter. Safemapping.add ("*", typeof (byte []));

// Map HIREDATE to a string // If the column name in the EMPINFO table is case-sensitive, // the safe type mapping column name must be case-sensitive.adapter.SafeMapping.Add ( "HIREDATE", typeof (string) );

// Map EMPNO to a string // If the column name in the EMPINFO table is case-sensitive, // the safe type mapping column name must also be case-sensitive.adapter.SafeMapping.Add ( "EMPNO", typeof (string ));

// create and fill the dataset using the EmpinfodataSet DataSet = new dataset (); adapter.fill (Dataset, "Empinfo");

// Get the Empinfo Table from the datasetdatatable table = dataset.tables ["Empinfo"]; // Get The first row from the Empinfo TableDataRow Row0 = Table.Rows [0];

// Print Out The Row Infoconsole.writeline ("Empno Column: Type =" ROW0 ["Empno"]. Gettype () "; value =" row0 ["Empno"]); console.writeline ("Empname Column : type = " row0 [" Empname "]. gettype () "; value = " row0 [" EmpName "]); console.writeline (" HiRedate Column: Type = " ROW0 [" HiRedate "]. Gettype () "; value =" row0 ["HiRedate"]); console.writeline ("Salary Column: Type =" ROW0 ["Salary"]. gettype () "; value =" row0 ["Salary "]);

Output: EMPNO Column: type = System.String; value = 1EMPNAME Column: type = System.String; value = KINGHIREDATE Column: type = System.String; value = 01-MAY-81SALARY Column: type = System.Byte []; Value = system.byte []

转载请注明原文地址:https://www.9cbs.com/read-90355.html

New Post(0)