Exemple #1
0
        /// <summary>
        /// Call a SQL's Procedure to get data
        /// </summary>
        /// <param name="ProcudureName">Procedure Name</param>
        /// <param name="ParameterList">Input Parameter [@Param=value]</param>
        /// <returns></returns>
        public static List <SList> CallProcedure(String ProcudureName, params Object[] ParameterList)
        {
            List <SList>  lstResult = new List <SList>();
            SqlDataReader readerDevice;

            SQLCompactFunctions(delegate()
            {
                String[] arrParam = new String[ParameterList.Length];

                SqlCommand queryCommand  = new SqlCommand(ProcudureName, SQLConnect);
                queryCommand.CommandType = CommandType.StoredProcedure;

                for (int i = 0; i < ParameterList.Length; i++)
                {
                    arrParam = ParameterList[i].ToString().Split('=');
                    queryCommand.Parameters.AddWithValue(arrParam[0], arrParam[1]);
                }

                readerDevice = queryCommand.ExecuteReader();

                if (readerDevice.HasRows)
                {
                    while (readerDevice.Read())
                    {
                        SList resultItem = new SList();
                        for (int i = 0; i < readerDevice.FieldCount; i++)
                        {
                            resultItem.Add(readerDevice.GetName(i), readerDevice[i].ToString());
                        }
                        lstResult.Add(resultItem);
                    }
                }
            });
            return(lstResult);
        }
Exemple #2
0
        /// <summary>
        /// Simple Query (Get data)
        /// </summary>
        /// <param name="Query">Query String</param>
        /// <param name="ParameterList">Input Parameter</param>
        /// <returns></returns>
        public static List <SList> SelectQuery(String Query, params Object[] ParameterList)
        {
            List <SList> lstResult = new List <SList>();

            SQLCompactFunctions(delegate()
            {
                SqlDataReader readerDevice;
                SqlCommand queryCommand = new SqlCommand(Query, SQLConnect);
                int countParam          = 0;
                List <String> arrParamName;

                //Count Param
                countParam = ParamCount(Query);

                //Get Param Name
                arrParamName = GetParamList(Query);

                //Add Param
                for (int i = 0; i < countParam; i++)
                {
                    queryCommand.Parameters.AddWithValue(arrParamName[i], ParameterList[i]);
                }

                readerDevice = queryCommand.ExecuteReader();

                //Kiem tra thu cho nay
                if (readerDevice.HasRows)
                {
                    while (readerDevice.Read())
                    {
                        SList resultItem = new SList();
                        for (int i = 0; i < readerDevice.FieldCount; i++)
                        {
                            resultItem.Add(readerDevice.GetName(i), readerDevice[i].ToString());
                        }
                        lstResult.Add(resultItem);
                    }
                }
            });
            return(lstResult);
        }