Example #1
0
        public DataTable ExcuteNonQuery(string query)
        {
            Array parameterList = MParameterList.ToArray();

            MParameterList.Clear();
            using (SqlConnection con = new SqlConnection(CONNECTION_STRING))
            {
                try
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    SqlDataAdapter sqlAdptr = new SqlDataAdapter(query, con);
                    if (parameterList.Length > 0)
                    {
                        sqlAdptr.SelectCommand.Parameters.AddRange(parameterList);
                    }
                    DataTable dataTable = new DataTable();
                    sqlAdptr.Fill(dataTable);

                    return(dataTable);
                }
                catch (Exception ex)
                {
                    // ex.ToWriteLog(Environment.StackTrace);
                    msg = ex.Message;
                    return(null);
                }
            }
        }
Example #2
0
        public object ExcuteScalar(string query)
        {
            Array parameterList = MParameterList.ToArray();

            MParameterList.Clear();
            using (SqlConnection con = new SqlConnection(CONNECTION_STRING))
            {
                try
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    SqlCommand cmd = new SqlCommand(query, con);
                    if (parameterList.Length > 0)
                    {
                        cmd.Parameters.AddRange(parameterList);
                    }
                    object obj = cmd.ExecuteScalar();
                    return(obj);
                }
                catch (Exception ex)
                {
                    //ex.ToWriteLog(Environment.StackTrace);
                    msg = ex.Message;
                    return(null);
                }
            }
        }