예제 #1
0
        public DataSet SpCaller(string name, List <P> parameters = null, IDictionary <object, object> requestitem = null, string Connectionstring = null)
        {
            if (requestitem != null && requestitem.Count > 0)
            {
                foreach (var item in requestitem)
                {
                    if (item.Key.GetType().Name == "String")
                    {
                        parameters.Add(new P {
                            Key = (string)item.Key, Value = (string)item.Value
                        });
                    }
                }
            }
            ;

            var me = new SpCallerModel
            {
                Name       = name,
                Parameters = parameters,
                //RequestItem = requestitem,
                Connectionstring = Connectionstring
            };

            return(SpCaller(me));
        }
예제 #2
0
        public string SpCallerV2(Action <SpCallerModel> action)
        {
            SpCallerModel model = new SpCallerModel();

            action.Invoke(obj: model);

            if (model.Connectionstring == null)
            {
                model.Connectionstring = appSettings.Database.WEBConnectionString;
            }

            using SqlConnection connection = new SqlConnection(model.Connectionstring);
            DataSet    ds  = new DataSet();
            SqlCommand cmd = new SqlCommand()
            {
                CommandType = CommandType.StoredProcedure,
                Connection  = connection,
                CommandText = model.Name
            };

            if (model.Parameters != null)
            {
                for (short i = 0; i < model.Parameters.Count; i++)
                {
                    SeperatesParam(cmd: cmd, args: model.Parameters[i], Connectionstring: model.Connectionstring);
                }
            }

            try
            {
                connection.Open();
                using SqlDataReader rdr = cmd.ExecuteReader();

                if (model.CompressPayload)
                {
                    return(SerializeDrToDicWithCompressPayload(rdr).ToJsonString());
                }
                else
                {
                    return(SerializeDrToDic(rdr).ToJsonString());
                }
            }
            catch (Exception ex) { throw ex; }
        }
예제 #3
0
        public DataSet SpCaller(SpCallerModel model)
        {
            if (model.Connectionstring == null)
            {
                model.Connectionstring = appSettings.Database.WEBConnectionString;
            }

            DataSet       ds         = new DataSet();
            SqlConnection connection = new SqlConnection(model.Connectionstring);
            SqlCommand    cmd        = new SqlCommand()
            {
                CommandType = CommandType.StoredProcedure,
                Connection  = connection,
                CommandText = model.Name
            };

            if (model.Parameters != null)
            {
                for (short i = 0; i < model.Parameters.Count; i++)
                {
                    SeperatesParam(cmd: cmd, args: model.Parameters[i], Connectionstring: model.Connectionstring);
                }
            }

            try
            {
                using SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);
            }
            catch (Exception ex) { throw ex; }
            finally
            {
                connection.Close();
                connection.Dispose();
            }
            return(ds);
        }