Esempio n. 1
0
        private static SqlParameter[] getSPParameters(string connectString, string spName, bool includeReturnValue)
        {
            SqlParameterCollection spParameters = null;

            SqlParameter[] arr;
            spParameters = getFromCach(spName);


            if (spParameters != null)
            {
                arr = new SqlParameter[spParameters.Count];
                spParameters.CopyTo(arr, 0);
                return(arr);
            }
            using (SqlConnection mcn = new SqlConnection(connectString))
            {
                mcn.Open();
                using (SqlCommand cmd = new SqlCommand(spName))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection  = mcn;
                    SqlCommandBuilder.DeriveParameters(cmd);
                    if (!includeReturnValue)
                    {
                        cmd.Parameters.RemoveAt(0);
                    }
                    spParameters = cmd.Parameters;//.CopyTo(spParameters, 0);
                    Cach(spName, spParameters);
                }
            }
            arr = new SqlParameter[spParameters.Count];
            spParameters.CopyTo(arr, 0);
            return(arr);
        }
Esempio n. 2
0
 public IEnumerable <SqlParameter> GetSqlParameters()
 {
     using (SqlCommand cmd = new SqlCommand())
     {
         sqlParams = cmd.Parameters;
         AddSqlParameter(this);
         SqlParameter[] arrSqlParams = new SqlParameter[sqlParams.Count];
         sqlParams.CopyTo(arrSqlParams, 0);
         cmd.Parameters.Clear();
         return(arrSqlParams);
     }
 }
        public void ConnectionCopyTo()
        {
            SqlCommand             command    = new SqlCommand();
            SqlParameterCollection collection = command.Parameters;

            collection.Add(new SqlParameter("Test1", 1));
            collection.Add(new SqlParameter("Test2", 2));

            SqlParameter[] copied = new SqlParameter[2];
            collection.CopyTo(copied, 0);

            Assert.Equal(collection[0], copied[0]);
            Assert.Equal(collection[1], copied[1]);
        }
Esempio n. 4
0
File: DB.cs Progetto: radtek/eReim
 public int ExeSql(String SqlStr, SqlParameterCollection ParColl)
 {
     SqlParameter[] sqlp = new SqlParameter[ParColl.Count];
     ParColl.CopyTo(sqlp, 0);
     return(ExeSql(SqlStr, sqlp));
 }
Esempio n. 5
0
 public static IEnumerable <T> List <T>(string query, SqlParameterCollection parameter) where T : new()
 {
     SqlParameter[] obj = new SqlParameter[parameter.Count];
     parameter.CopyTo(obj, 0);
     return(List <T>(query, string.Empty, obj));
 }