Example #1
0
        public static Boolean AddParameter(SqlCommand parCMD, TTDictionary lstParamters, object objEntity)
        {
            Boolean blnResult = false;

            //TTAttributs MyAttributs = (TTAttributs)obj.GetType().GetProperty(parPropertyName).GetCustomAttribute(typeof(TTAttributs), false);

            for (int i = 0; i < lstParamters.Count(); i++)
            {
                var         el          = lstParamters.ElementAt(i);
                TTAttributs MyAttributs = HelperMethod.GetTTAttributes(objEntity, el.Key);
                object      objValue    = el.Value.Value1;
                if (MyAttributs.ParamaterDataType == SqlDbType.NVarChar)
                {
                    int parFieldWidth = ((MaxLengthAttribute)(objEntity.GetType().GetProperty(el.Key).GetCustomAttributes(typeof(MaxLengthAttribute), true)[0])).Length;
                    if (MyAttributs.isMemoField == false)
                    {
                        parCMD.Parameters.Add("@" + MyAttributs.FieldName, MyAttributs.ParamaterDataType, parFieldWidth).Value = objValue == null ? string.Empty : objValue;
                    }
                    else
                    {
                        parFieldWidth = objEntity.ToString().Length;
                        parCMD.Parameters.Add("@" + MyAttributs.FieldName, MyAttributs.ParamaterDataType, parFieldWidth).Value = objValue == null ? string.Empty : objValue;
                    }
                }
                else
                {
                    parCMD.Parameters.Add("@" + MyAttributs.FieldName, MyAttributs.ParamaterDataType).Value = objValue;
                }
            }
            return(blnResult);
        }
Example #2
0
        public static StringBuilder GetParameter(TTDictionary FieldCollection, StringBuilder sb)
        {
            StringBuilder sbResult = new StringBuilder();

            for (int i = 0; i < FieldCollection.Count(); i++)
            {
                var el = FieldCollection.ElementAt(i);
                sbResult.Append(" " + el.Value.Value2 + " " + el.Key + " " + el.Value.value3 + " @" + el.Key);
            }
            return(sbResult);
        }