我用了 Oracle.ManagedDataAccess.Client
string connectionString = "。。。";
using (OracleConnection conn = new OracleConnection(connectionString))
{
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
//OracleTransaction transaction = conn.BeginTransaction();
try
{
using (OracleCommand com = new OracleCommand())
{
foreach (HosDept dept in listDepts)
{
string sql = "。。。";
OracleParameter[] par = new OracleParameter[13];
。。。
par[12] = new OracleParameter("DESCRIPTION", dept.Desc);
com.Parameters.AddRange(par);
//com.Transaction = transaction;
com.CommandType = CommandType.Text;
com.CommandText = sql;
com.ExecuteNonQuery();
}
}
}
catch (Exception e)
{
//transaction.Rollback();
throw e;
}
这样执行报错,报错内容如下:
{System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Oracle.ManagedDataAccess.Client.OracleCommand.ValidateStatePriorToExecution()
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteScalar()
at PlatformAdmin.DBUtils.DeptsDAL.CreateHosDepts(List`1 listDepts) in C:\Users\HY\Desktop\projects\SRC\CapInfo.BJHL\RealtimeBiz\CenterSide\WeChat\HisAdapterApi\PlatformAdmin\DBUtils\DeptsDAL.cs:line 51}
com没有连接对象,把conn付给com就可以了