Esempio n. 1
0
        /// <summary>
        /// 带参数可执行TSQL
        /// </summary>
        /// <returns></returns>
        public string ExecuteTSql()
        {
            var temp       = @"DECLARE {0} {1};SET {0} = '{2}';";
            var parameters = GetParameters();
            var sqlSb      = new StringBuilder();

            foreach (var item in parameters)
            {
                var v = item.Value.GetType();
                if (!DataType.ContainsKey(v))
                {
                    throw new Exception($"不支持类型转TSQL:【{v.Name}】");
                }
                var valueType = DataType[v];
                if (v.Equals(typeof(string)))
                {
                    valueType = string.Format(valueType, ((string)item.Value).Length);
                }
                sqlSb.AppendFormat(temp, item.Key, valueType, item.Value);
            }
            sqlSb.AppendLine(_SQL);
            return(sqlSb.ToString());
        }