Beispiel #1
0
        private string AttachParametersErr(string CommandText, ParameterMember param, ref string Query)
        {
            if (param == null)
            {
                return(CommandText);
            }
            CommandText = CommandText.Replace("\t", "");
            CommandText = CommandText.Replace(",", " ,") + " ";
            string ParmData = "";

            ParmData  = "================================================================================================\n";
            ParmData += CommandText + "\n";
            ParmData += "================================================================================================\n";


            for (int i = 0; i < param.Count; i++)
            {
                ParmData += "\t" + param.GetName(i) + "\t='" + param.GetValue(i) + "' \n";

                CommandText = CommandText.Replace(param.GetName(i) + " ", "'" + param.GetValue(i) + "'");
            }
            CommandText = CommandText.Replace("  ", "");
            ParmData   += "================================================================================================\n";
            Query       = CommandText;
            CommandText = ParmData + CommandText;
            return(CommandText);
            //Console.WriteLine(command.CommandText.ToString());
        }
Beispiel #2
0
        private void AssignParameterValues(SqlParameter[] commandParameters, ParameterMember parameterValues)
        {
            if ((commandParameters == null) || (parameterValues == null))
            {
                return;
            }

            // we must have the same number of values as we pave parameters to put them in
            if (commandParameters.Length != parameterValues.Count)
            {
                throw new ArgumentException("Parameter count does not match Parameter Value count.");
            }

            int i = 0;

            foreach (SqlParameter p in commandParameters)
            {
                if (p.ParameterName.ToUpper() != parameterValues.GetName(i++).ToUpper())
                {
                    throw new ArgumentException("ParameterName does not match ParamterMember Name");
                }
            }

            //iterate through the SqlParameters, assigning the values from the corresponding position in the
            //value array
            i = 0;
            for (int j = commandParameters.Length; i < j; i++)
            {
                commandParameters[i].Value = parameterValues.GetValue(i);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Command객체에 Parameter를 추가한다.
        /// </summary>
        /// <param name="command"></param>
        /// <param name="param"></param>
        private void AttachParameters(SqlCommand command, ParameterMember param)
        {
            if (param == null)
            {
                return;
            }

            for (int i = 0; i < param.Count; i++)
            {
                SqlParameter cmdPara = new SqlParameter(param.GetName(i), param.GetType(i));
                cmdPara.Value = param.GetValue(i);

                command.Parameters.Add(cmdPara);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Command객체에 Parameter를 추가한다.
        /// </summary>
        /// <param name="command"></param>
        /// <param name="param"></param>
        private void AttachParameters(OleDbCommand command, ParameterMember param)
        {
            if (param == null)
            {
                return;
            }
            for (int i = 0; i < param.Count; i++)
            {
                OleDbParameter cmdPara = new OleDbParameter(param.GetName(i), param.GetType(i));

                cmdPara.Value = param.GetValue(i);

                if (command.CommandType != CommandType.StoredProcedure)
                {
                    command.CommandText = command.CommandText.Replace(param.GetName(i) + " ", "? ");
                }
                else
                {
                    command.CommandText = command.CommandText.Replace(param.GetName(i), "");
                }
                command.Parameters.Add(cmdPara);
            }
            //Console.WriteLine(command.CommandText.ToString());
        }