关于Oracle.DataAccess.Client.OracleConnection的类型初始值设定项引发异常
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using (OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["NSBD_SHUJUKU"].ConnectionString)) { conn.Open(); OracleTransaction trans = conn.BeginTransaction(); try { OracleCommand command = new OracleCommand(); command.Connection = conn; //到此为止跟我们,使用的基本一样 //然后需要添加参数了 command.ArrayBindCount = batchCount; //注意参数写法: string insert = string.Format("insert into {0} (spointguid,dsdate{1},srcnote,errnote) values(:spointguid, :dsdate", tableName, fieldNames); string[] guids = guidList.GetRange(startIndex, batchCount).ToArray(); DateTime[] dates = dateLists.GetRange(startIndex, batchCount).ToArray(); List<string[]> values = new List<string[]>(); for (int i = 0; i < fieldNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Length; i++) { insert += ",:V" + i.ToString(); values.Add(valueDics[i].ToArray()); } insert += ",:srcNote,:errNote)"; command.CommandText = insert; // 添加参数 OracleParameter guidParam = new OracleParameter("spointguid", OracleDbType.Varchar2); guidParam.Direction = ParameterDirection.Input; guidParam.Value = guids; command.Parameters.Add(guidParam); OracleParameter dateParam = new OracleParameter("dsdate", OracleDbType.Date); dateParam.Direction = ParameterDirection.Input; dateParam.Value = dates; command.Parameters.Add(dateParam); for (int i = 0; i < values.Count; i++) { OracleParameter valueParam = new OracleParameter("V" + i.ToString(), OracleDbType.Single); valueParam.Direction = ParameterDirection.Input; valueParam.Value = values[i]; command.Parameters.Add(valueParam); } OracleParameter srcNoteParam = new OracleParameter("srcnote", OracleDbType.Char); srcNoteParam.Direction = ParameterDirection.Input; srcNoteParam.Value = srcNote.ToArray(); command.Parameters.Add(srcNoteParam); OracleParameter errNoteParam = new OracleParameter("errcnote", OracleDbType.Char); errNoteParam.Direction = ParameterDirection.Input; errNoteParam.Value = errNote.ToArray(); command.Parameters.Add(errNoteParam); correctRows += command.ExecuteNonQuery(); trans.Commit(); conn.Close(); command.Dispose(); } catch (Exception ex) { trans.Rollback(); // throw; } finally { conn.Close(); } } #endregion } return correctRows; }
然后运行会有错误,当然,cs文件上边的引用已经弄好
然后这个问题我遇到的是,需要把这4个文件,拷到程序运行exe的同级目录(bin\debug)
然后在运行就通过了
这个是解决了,看好多帖子,别人的都是需要,OraOps10还有11的版本问题