SafeMapping

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[]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值