日期:2014-05-17 浏览次数:20874 次
//放在一起的话,你如果要返回值,需写sp去执行
//下面是本机测试的简单例子
using System;
using System.Data.SqlClient;
using System.Data.OracleClient;
public class Test
{
/*
建表及序列
create table t(id int);
create sequence t_seq;
*/
public static void Main()
{
OracleConnection conn = null;
OracleCommand cmd = null;
int val = 0;
const string sConn = "data source=orcl;user id=zhangjg;password=1;";
try
{
conn = new OracleConnection(sConn);
cmd = new OracleCommand("insert into t values(t_seq.nextval)", conn);
conn.Open();
cmd.ExecuteNonQuery();
cmd = new OracleCommand("select t_seq.currval from dual", conn);
val = Convert.ToInt32(cmd.ExecuteScalar());
}
catch (Exception err)
{
Console.Write(err.Message);
}
finally
{
conn.Close();
}
Console.WriteLine(val);
Console.ReadKey();
}
}