//publClass1.csic override int ExecuteSql(string Sql, List<ImageParameter> ImagePar) //{ // SqlCommand cmd = new SqlCommand(); // cmd.Connection = privateconn; // cmd.Transaction = ts; // cmd.CommandTimeout = 0; // cmd.CommandType = CommandType.Text; // cmd.CommandText = Sql; // for (int i = 0; i < ImagePar.Count; i++) // { // SqlParameter p = new SqlParameter(ImagePar[i].Name, SqlDbType.VarBinary, ImagePar[i].Value.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, ImagePar[i].Value); // cmd.Parameters.Add(p); // } // return cmd.ExecuteNonQuery(); //} public override int ExecuteProcedure(string ProcedureName, List<ProcedureParameter> ProcedurePar) { SqlCommand cmd = new SqlCommand(); cmd.Connection = privateconn; cmd.Transaction = ts; cmd.CommandTimeout = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = ProcedureName; for (int i = 0; i < ProcedurePar.Count; i++) { SqlParameter p = ParameterTransform(ProcedurePar[i]); cmd.Parameters.Add(p); } int result = cmd.ExecuteNonQuery(); for (int i = 0; i < cmd.Parameters.Count; i++) { switch (cmd.Parameters[i].Direction) { case ParameterDirection.InputOutput: case ParameterDirection.Output: case ParameterDirection.ReturnValue: ProcedurePar[i] = new ProcedureParameter(ProcedurePar[i].Name, ProcedurePar[i].ParType, ProcedurePar[i].Size, ProcedurePar[i].Direction, cmd.Parameters[i].Value); break; } } return result; }
/// <summary>参数类型转化</summary> /// <param name="Par"></param> /// <returns></returns> private SqlParameter ParameterTransform(ProcedureParameter Par) { /*车毅修改 支持无类型参数*/ if (Par.ParType == ProcParType.Default) return new SqlParameter(Par.Name, Par.Value); SqlParameter p = new SqlParameter(); p.ParameterName = Par.Name; switch (Par.ParType) { case ProcParType.Int16: p.SqlDbType = SqlDbType.SmallInt; break; case ProcParType.Int32: p.SqlDbType = SqlDbType.Int; break; case ProcParType.Int64: p.SqlDbType = SqlDbType.BigInt; break; case ProcParType.Single: p.SqlDbType = SqlDbType.Real; break; case ProcParType.Double: p.SqlDbType = SqlDbType.Float; break; case ProcParType.Decimal: p.SqlDbType = SqlDbType.Decimal; break; case ProcParType.Char: p.SqlDbType = SqlDbType.Char; break; case ProcParType.VarChar: p.SqlDbType = SqlDbType.VarChar; break; case ProcParType.NVarchar: p.SqlDbType = SqlDbType.NVarChar; break; case ProcParType.Image: p.SqlDbType = SqlDbType.Binary; break; case ProcParType.DateTime: p.SqlDbType = SqlDbType.DateTime; break; default: throw new Exception("未知类型ProcParType:" + Par.ParType.ToString()); } p.Size = Par.Size; p.Direction = Par.Direction; switch (Par.Direction) { case ParameterDirection.Input: case ParameterDirection.InputOutput: if (Par.Value == null) { p.Value = DBNull.Value; } else { p.Value = Par.Value; } break; } return p; }
/// <summary>参数类型转化</summary> /// <param name="Par"></param> /// <returns></returns> private SqlParameter ParameterTransform(ProcedureParameter Par) { /*车毅修改 支持无类型参数*/ if (Par.ParType == ProcParType.Default) { return(new SqlParameter(Par.Name, Par.Value)); } SqlParameter p = new SqlParameter(); p.ParameterName = Par.Name; switch (Par.ParType) { case ProcParType.Int16: p.SqlDbType = SqlDbType.SmallInt; break; case ProcParType.Int32: p.SqlDbType = SqlDbType.Int; break; case ProcParType.Int64: p.SqlDbType = SqlDbType.BigInt; break; case ProcParType.Single: p.SqlDbType = SqlDbType.Real; break; case ProcParType.Double: p.SqlDbType = SqlDbType.Float; break; case ProcParType.Decimal: p.SqlDbType = SqlDbType.Decimal; break; case ProcParType.Char: p.SqlDbType = SqlDbType.Char; break; case ProcParType.VarChar: p.SqlDbType = SqlDbType.VarChar; break; case ProcParType.NVarchar: p.SqlDbType = SqlDbType.NVarChar; break; case ProcParType.Image: p.SqlDbType = SqlDbType.Binary; break; case ProcParType.DateTime: p.SqlDbType = SqlDbType.DateTime; break; default: throw new Exception("未知类型ProcParType:" + Par.ParType.ToString()); } p.Size = Par.Size; p.Direction = Par.Direction; switch (Par.Direction) { case ParameterDirection.Input: case ParameterDirection.InputOutput: if (Par.Value == null) { p.Value = DBNull.Value; } else { p.Value = Par.Value; } break; } return(p); }
//public override int ExecuteSql(string Sql, List<ImageParameter> ImagePar) //{ // OracleCommand cmd = new OracleCommand(); // cmd.Connection = privateconn; // cmd.Transaction = ts; // cmd.CommandTimeout = 0; // cmd.CommandType = CommandType.Text; // cmd.CommandText = Sql; // for (int i = 0; i < ImagePar.Count; i++) // { // OracleParameter p = new OracleParameter(ImagePar[i].Name, OracleType.Blob, ImagePar[i].Value.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, ImagePar[i].Value); // cmd.Parameters.Add(p); // } // return cmd.ExecuteNonQuery(); //} public override int ExecuteProcedure(string ProcedureName, List <ProcedureParameter> ProcedurePar) { OracleCommand cmd = new OracleCommand(); cmd.Connection = privateconn; cmd.Transaction = ts; cmd.CommandTimeout = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = ProcedureName; for (int i = 0; i < ProcedurePar.Count; i++) { OracleParameter p = new OracleParameter(); p.ParameterName = ProcedurePar[i].Name; switch (ProcedurePar[i].ParType) { case ProcParType.Int16: p.OracleType = OracleType.Int16; break; case ProcParType.Int32: p.OracleType = OracleType.Int32; break; case ProcParType.Int64: p.OracleType = OracleType.Number; break; case ProcParType.Single: p.OracleType = OracleType.Float; break; case ProcParType.Double: p.OracleType = OracleType.Double; break; case ProcParType.Decimal: p.OracleType = OracleType.Number; break; case ProcParType.Char: p.OracleType = OracleType.Char; break; case ProcParType.VarChar: p.OracleType = OracleType.VarChar; break; case ProcParType.NVarchar: p.OracleType = OracleType.NVarChar; break; case ProcParType.Image: p.OracleType = OracleType.Blob; break; case ProcParType.DateTime: p.OracleType = OracleType.DateTime; break; default: throw new Exception("未知类型ProcParType:" + ProcedurePar[i].ParType.ToString()); } p.Size = ProcedurePar[i].Size; p.Direction = ProcedurePar[i].Direction; switch (ProcedurePar[i].Direction) { case ParameterDirection.Input: case ParameterDirection.InputOutput: p.Value = ProcedurePar[i].Value; break; } cmd.Parameters.Add(p); } int result = cmd.ExecuteNonQuery(); for (int i = 0; i < cmd.Parameters.Count; i++) { switch (cmd.Parameters[i].Direction) { case ParameterDirection.InputOutput: case ParameterDirection.Output: case ParameterDirection.ReturnValue: ProcedurePar[i] = new ProcedureParameter(ProcedurePar[i].Name, ProcedurePar[i].ParType, ProcedurePar[i].Size, ProcedurePar[i].Direction, cmd.Parameters[i].Value); break; } } return(result); }
//public override int ExecuteSql(string Sql, List<ImageParameter> ImagePar) //{ // OracleCommand cmd = new OracleCommand(); // cmd.Connection = privateconn; // cmd.Transaction = ts; // cmd.CommandTimeout = 0; // cmd.CommandType = CommandType.Text; // cmd.CommandText = Sql; // for (int i = 0; i < ImagePar.Count; i++) // { // OracleParameter p = new OracleParameter(ImagePar[i].Name, OracleType.Blob, ImagePar[i].Value.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, ImagePar[i].Value); // cmd.Parameters.Add(p); // } // return cmd.ExecuteNonQuery(); //} public override int ExecuteProcedure(string ProcedureName, List<ProcedureParameter> ProcedurePar) { OracleCommand cmd = new OracleCommand(); cmd.Connection = privateconn; cmd.Transaction = ts; cmd.CommandTimeout = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = ProcedureName; for (int i = 0; i < ProcedurePar.Count; i++) { OracleParameter p = new OracleParameter(); p.ParameterName = ProcedurePar[i].Name; switch (ProcedurePar[i].ParType) { case ProcParType.Int16: p.OracleType = OracleType.Int16; break; case ProcParType.Int32: p.OracleType = OracleType.Int32; break; case ProcParType.Int64: p.OracleType = OracleType.Number; break; case ProcParType.Single: p.OracleType = OracleType.Float; break; case ProcParType.Double: p.OracleType = OracleType.Double; break; case ProcParType.Decimal: p.OracleType = OracleType.Number; break; case ProcParType.Char: p.OracleType = OracleType.Char; break; case ProcParType.VarChar: p.OracleType = OracleType.VarChar; break; case ProcParType.NVarchar: p.OracleType = OracleType.NVarChar; break; case ProcParType.Image: p.OracleType = OracleType.Blob; break; case ProcParType.DateTime: p.OracleType = OracleType.DateTime; break; default: throw new Exception("未知类型ProcParType:" + ProcedurePar[i].ParType.ToString()); } p.Size = ProcedurePar[i].Size; p.Direction = ProcedurePar[i].Direction; switch (ProcedurePar[i].Direction) { case ParameterDirection.Input: case ParameterDirection.InputOutput: p.Value = ProcedurePar[i].Value; break; } cmd.Parameters.Add(p); } int result = cmd.ExecuteNonQuery(); for (int i = 0; i < cmd.Parameters.Count; i++) { switch (cmd.Parameters[i].Direction) { case ParameterDirection.InputOutput: case ParameterDirection.Output: case ParameterDirection.ReturnValue: ProcedurePar[i] = new ProcedureParameter(ProcedurePar[i].Name, ProcedurePar[i].ParType, ProcedurePar[i].Size, ProcedurePar[i].Direction, cmd.Parameters[i].Value); break; } } return result; }