SafeMapping

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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 following example shows how to use the SafeMapping property to fill the dataset

public static void UseSafeMapping(

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 string

OracleDataAdapter adapter = new OracleDataAdapter(cmdStr, connStr);

//get the connection from the adapter

OracleConnection 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 EMPINFO

DataSet dataset = new DataSet();

adapter.Fill(dataset, "EMPINFO");

//Get the EMPINFO table from the dataset

DataTable table = dataset.Tables["EMPINFO"];

//Get the first row from the EMPINFO table

DataRow row0 = table.Rows[0];

//Print out the row info

Console.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 = 1

EMPNAME Column: type = System.String; value = KING

HIREDATE Column: type = System.String; value = 01-MAY-81

SALARY Column: type = System.Byte[]; value = System.Byte[]

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航