当前位置: 首页>>代码示例>>C#>>正文


C# DAL.ExecuteNonQuery方法代码示例

本文整理汇总了C#中DAL.ExecuteNonQuery方法的典型用法代码示例。如果您正苦于以下问题:C# DAL.ExecuteNonQuery方法的具体用法?C# DAL.ExecuteNonQuery怎么用?C# DAL.ExecuteNonQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DAL的用法示例。


在下文中一共展示了DAL.ExecuteNonQuery方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnAddProd_Click

    void btnAddProd_Click(object sender, EventArgs e)
    {
        try
        {
            Random rnd = new Random();
            string appendStr = rnd.Next(11111, 99999).ToString();
            DAL obj = new DAL(ConnectionString);
            DeleteExists(obj, txtProdName.Text.Replace("'", "''"));
            string bigImgPath = "images/Uploaded/" + appendStr + "_" + fileBigImage.PostedFile.FileName;
            string mainImgPath = "images/Uploaded/" + appendStr + "_" + fileMainImg.PostedFile.FileName;
            string images = "images/Uploaded/" + appendStr + "_" + fileImages.PostedFile.FileName;

            fileBigImage.PostedFile.SaveAs(Server.MapPath(bigImgPath));
            fileMainImg.PostedFile.SaveAs(Server.MapPath(mainImgPath));
            fileImages.PostedFile.SaveAs(Server.MapPath(images));

            int prodID = 0;
            DataTable dt = new DAL(ConnectionString).ExecuteQuery("SELECT MAX(PRODUCT_ID) FROM PRODUCTS_LIST");
            if (dt.Rows[0][0] != DBNull.Value)
                prodID = Convert.ToInt16(dt.Rows[0][0]);
            prodID++;

            obj.ExecuteNonQuery("INSERT INTO PRODUCTS_LIST(PRODUCT_NAME,PRODUCT_ID,PRODUCT_CAT,MAIN_IMAGE,SUB_TEXT,BIG_IMAGE) VALUES('" +
                 txtProdName.Text.Replace("'", "''") + "','" +
                 prodID.ToString() + "','" +
                 txtProductCat.Text.Replace("'", "''") + "','" +
                 mainImgPath.Replace("'", "''") + "','" +
                 txtProdTitle.Text.Replace("'", "''") + "','" +
                 bigImgPath.Replace("'", "''") + "')");
            obj.ExecuteNonQuery("INSERT INTO PRODUCTS_DETAILS(PRODUCT_ID,IMG_PATH,IMG_ALT_NAME,MAIN_BODY) VALUES('" +
                 prodID.ToString() + "','" +
                 images.Replace("'", "''") + "','" +
                 txtProdName.Text.Replace("'", "''") + "','" +
                 taFinalText.Text.Replace("'", "''") + "')");

            string productMenu = obj.ExecuteQuery("SELECT MENU_ID FROM MAIN_MENU WHERE MENU_NAME='PRODUCTS'").Rows[0][0].ToString();
            try
            {
                dt = obj.ExecuteQuery("SELECT MENU_ID FROM MAIN_MENU WHERE PARENT_ID='" + productMenu + "'");
                foreach (DataRow dr in dt.Rows)
                {
                    int count1 = Convert.ToInt16(obj.ExecuteQuery("SELECT COUNT(*) FROM MAIN_MENU WHERE PARENT_ID='" + dr[0] + "'").Rows[0][0]);
                    if (count1 == 0)
                        obj.ExecuteNonQuery("DELETE FROM MAIN_MENU WHERE MENU_ID='" + dr[0] + "'");
                }
            }
            catch (Exception)
            {
            }
            int menuID = Convert.ToInt16(new DAL(ConnectionString).ExecuteQuery("SELECT MAX(MENU_ID) FROM MAIN_MENU").Rows[0][0]);
            menuID++;

            int count = Convert.ToInt16(obj.ExecuteQuery("SELECT COUNT(MENU_ID) FROM MAIN_MENU WHERE MENU_NAME='" + txtProductCat.Text + "'").Rows[0][0]);
            string parentID = "";
            if (count == 0)
            {
                obj.ExecuteNonQuery("INSERT INTO MAIN_MENU(MENU_NAME,MENU_ID,PARENT_ID) VALUES('" + txtProductCat.Text.Replace("'", "''") + "','" + menuID.ToString() + "','" + productMenu + "')");
                parentID = menuID.ToString();
                menuID++;
            }
            else
                parentID = obj.ExecuteQuery("SELECT MENU_ID FROM MAIN_MENU WHERE MENU_NAME='" + txtProductCat.Text + "'").Rows[0][0].ToString();

            obj.ExecuteNonQuery("INSERT INTO MAIN_MENU(MENU_NAME,MENU_ID,PARENT_ID,URL) VALUES('" + txtProdName.Text.Replace("'", "''") + "','" + menuID.ToString() + "','" + parentID + "','productdetails.aspx?product=" + prodID.ToString() + "')");

        }
        catch (Exception)
        {
            throw;
        }
    }
开发者ID:pradeepgade,项目名称:ushodaya,代码行数:71,代码来源:AdminCustomise.aspx.cs

示例2: DeleteExists

    private void DeleteExists(DAL obj, string productName)
    {
        try
        {
            int count = Convert.ToInt16(obj.ExecuteQuery("SELECT COUNT(*) FROM PRODUCTS_LIST WHERE PRODUCT_NAME='" + productName + "'").Rows[0][0]);
            if (count > 0)
            {
                count = Convert.ToInt16(obj.ExecuteQuery("SELECT PRODUCT_ID FROM PRODUCTS_LIST WHERE PRODUCT_NAME='" + productName + "'").Rows[0][0]);
                obj.ExecuteNonQuery("DELETE FROM PRODUCTS_DETAILS WHERE PRODUCT_ID=" + count.ToString());
                obj.ExecuteNonQuery("DELETE FROM PRODUCTS_LIST WHERE PRODUCT_NAME='" + productName + "'");
                obj.ExecuteNonQuery("DELETE FROM MAIN_MENU WHERE MENU_NAME='" + productName + "'");
            }

        }
        catch (Exception)
        {
            throw;
        }
    }
开发者ID:pradeepgade,项目名称:ushodaya,代码行数:19,代码来源:AdminCustomise.aspx.cs

示例3: DeleteMovie

        /// <summary>
        /// Delete a person
        /// </summary>
        /// <param name="id"></param>
        public void DeleteMovie(string id)
        {
            using(DAL dal = new DAL(this._cfg)) {
                dal.OpenConnection();

                DbCommand cmd = dal.CreateCommand();

                // delete movie
                cmd.CommandText = "DELETE";
                cmd.CommandText += " FROM tbl_movies";

                if(this._cfg.ProviderType != ProviderType.SQLite) {
                    cmd.CommandText += " WHERE pkid = '" + id + "'";
                }
                else {
                    cmd.CommandText += " WHERE lower(pkid) = lower('{" + id + "}'";
                }

                try {
                    dal.ExecuteNonQuery(cmd);
                }
                catch(Exception ex) {
                    throw ex;
                }

                // delete movie-category-link
                cmd.CommandText = "DELETE ";
                cmd.CommandText += " FROM tbl_movies_to_categories";

                if(this._cfg.ProviderType != ProviderType.SQLite) {
                    cmd.CommandText += " WHERE movie_pkid = '" + id + "'";
                }
                else {
                    cmd.CommandText += " WHERE lower(movie_pkid) = lower('{" + id + "}'";
                }

                try {
                    dal.ExecuteNonQuery(cmd);
                }
                catch(Exception ex) {
                    throw ex;
                }

                // delete movie-genre-link
                cmd.CommandText = "DELETE ";
                cmd.CommandText += " FROM tbl_movies_to_genres";

                if(this._cfg.ProviderType != ProviderType.SQLite) {
                    cmd.CommandText += " WHERE movie_pkid = '" + id + "'";
                }
                else {
                    cmd.CommandText += " WHERE lower(movie_pkid) = lower('{" + id + "}'";
                }

                try {
                    dal.ExecuteNonQuery(cmd);
                }
                catch(Exception ex) {
                    throw ex;
                }

                // delete movie-person-link
                cmd.CommandText = "DELETE ";
                cmd.CommandText += " FROM tbl_movies_to_persons";

                if(this._cfg.ProviderType != ProviderType.SQLite) {
                    cmd.CommandText += " WHERE movie_pkid = '" + id + "'";
                }
                else {
                    cmd.CommandText += " WHERE lower(movie_pkid) = lower('{" + id + "}'";
                }

                try {
                    dal.ExecuteNonQuery(cmd);
                }
                catch(Exception ex) {
                    throw ex;
                }
            }
        }
开发者ID:vandango,项目名称:MovieMatic,代码行数:84,代码来源:DataHandler.cs

示例4: CleanDatabase

        /// <summary>
        /// Cleans the database.
        /// </summary>
        /// <returns></returns>
        public bool CleanDatabase()
        {
            using(DAL dal = new DAL(this._cfg)) {
                dal.OpenConnection();

                DbCommand cmd = dal.CreateCommand();

                // clean empty genre-link entries
                cmd.CommandText = "DELETE ";
                cmd.CommandText += "FROM tbl_movies_to_genres ";
                cmd.CommandText += "WHERE pkid IN ( ";
                cmd.CommandText += "	SELECT mg.pkid ";
                cmd.CommandText += "	FROM tbl_movies_to_genres AS mg ";
                cmd.CommandText += "	LEFT JOIN tbl_movies AS m ";
                cmd.CommandText += "	ON mg.movie_pkid = m.pkid ";
                cmd.CommandText += "	WHERE m.pkid IS NULL";
                cmd.CommandText += ") ";

                try {
                    dal.ExecuteNonQuery(cmd);
                }
                catch(Exception ex) {
                    throw ex;
                }

                // clean empty category-link entries
                cmd.CommandText = "DELETE ";
                cmd.CommandText += "FROM tbl_movies_to_categories ";
                if(this._cfg.ProviderType != ProviderType.SQLite) {
                    cmd.CommandText += "WHERE (CAST(movie_pkid AS VARCHAR(MAX)) + CAST(category_pkid AS VARCHAR(MAX))) IN ( ";
                    cmd.CommandText += "	SELECT (CAST(mc.movie_pkid AS VARCHAR(MAX)) + CAST(mc.category_pkid AS VARCHAR(MAX))) ";
                }
                else {
                    cmd.CommandText += "WHERE (CAST(movie_pkid AS VARCHAR) + CAST(category_pkid AS VARCHAR)) IN ( ";
                    cmd.CommandText += "	SELECT (CAST(mc.movie_pkid AS VARCHAR) + CAST(mc.category_pkid AS VARCHAR)) ";
                }
                cmd.CommandText += "	FROM tbl_movies_to_categories AS mc ";
                cmd.CommandText += "	LEFT JOIN tbl_movies AS m ";
                cmd.CommandText += "	ON mc.movie_pkid = m.pkid ";
                cmd.CommandText += "	WHERE m.pkid IS NULL ";
                cmd.CommandText += ") ";

                try {
                    dal.ExecuteNonQuery(cmd);
                }
                catch(Exception ex) {
                    throw ex;
                }
            }

            return true;
        }
开发者ID:vandango,项目名称:MovieMatic,代码行数:56,代码来源:DataHandler.cs

示例5: CheckDatabaseVersion

        // -------------------------------------------------------
        // PUBLIC MEMBERS
        // -------------------------------------------------------
        /// <summary>
        /// Checks the database version.
        /// </summary>
        public void CheckDatabaseVersion()
        {
            if(this._cfg.ProviderType != ProviderType.SQLite) {
                using(DAL dal = new DAL(this._cfg)) {
                    dal.OpenConnection();

                    /*
                     * for version 1.1.4
                     */
                    bool hasSortValue = false;

                    DbCommand cmd114 = dal.CreateCommand();

                    if(this._cfg.ProviderType == ProviderType.SQLite) {
                        cmd114.CommandText = "SELECT* FROM tbl_movies LIMIT 1";
                    }
                    else {
                        cmd114.CommandText = "SELECT TOP 1 * FROM tbl_movies";
                    }

                    try {
                        using(IDataReader reader = dal.ExecuteQueryForDataReader(cmd114)) {
                            for(int i = 0; i < reader.FieldCount; i++) {
                                if(reader.GetName(i) == "sort_value") {
                                    hasSortValue = true;
                                    break;
                                }
                            }
                        }
                    }
                    catch(Exception ex) {
                        throw ex;
                    }

                    try {
                        if(!hasSortValue) {
                            cmd114.CommandText = "ALTER TABLE tbl_movies ";
                            cmd114.CommandText += "ADD	sort_value varchar(10) NULL;";
                            cmd114.CommandText += "ALTER TABLE tbl_movies ";
                            cmd114.CommandText += "ADD CONSTRAINT DF_tbl_movies_sort_value DEFAULT '' FOR sort_value;";

                            dal.ExecuteNonQuery(cmd114);
                        }
                    }
                    catch(Exception ex) {
                        throw ex;
                    }

                    /*
                     * for version 1.1.7
                     */
                    bool hasRoleName = false;
                    bool hasRoleType = false;

                    DbCommand cmd117 = dal.CreateCommand();
                    cmd117.CommandText = "SELECT TOP 1 * ";
                    cmd117.CommandText += "FROM tbl_movies_to_persons";

                    try {
                        using(IDataReader reader = dal.ExecuteQueryForDataReader(cmd117)) {
                            for(int i = 0; i < reader.FieldCount; i++) {
                                if(reader.GetName(i) == "role_name") {
                                    hasRoleName = true;
                                }

                                if(reader.GetName(i) == "role_type") {
                                    hasRoleType = true;
                                }

                                if(hasRoleName && hasRoleType) {
                                    break;
                                }
                            }
                        }
                    }
                    catch(Exception ex) {
                        throw ex;
                    }

                    try {
                        cmd117.CommandText = "";

                        if(!hasRoleName) {
                            cmd117.CommandText += "ALTER TABLE tbl_movies_to_persons ";
                            cmd117.CommandText += "ADD role_name nvarchar(max) NULL;";
                        }

                        if(!hasRoleType) {
                            cmd117.CommandText += "ALTER TABLE tbl_movies_to_persons ";
                            cmd117.CommandText += "ADD role_type int NULL;";
                        }

                        if(!string.IsNullOrEmpty(cmd117.CommandText)) {
                            dal.ExecuteNonQuery(cmd117);
//.........这里部分代码省略.........
开发者ID:vandango,项目名称:MovieMatic,代码行数:101,代码来源:DataHandler.cs

示例6: UpdatePersonRole

        /// <summary>
        /// Updates the person role.
        /// </summary>
        /// <param name="movieId">The movie id.</param>
        /// <param name="personId">The person id.</param>
        /// <param name="roleName">Name of the role.</param>
        /// <param name="roleType">Type of the role.</param>
        public void UpdatePersonRole(string movieId, string personId, string roleName, string roleType)
        {
            StringBuilder str = new StringBuilder();
            str.Append(" UPDATE tbl_movies_to_persons");
            str.Append(" SET role_name = @roleName, role_type = @roleType");
            str.Append(" WHERE movie_pkid = @movieId");
            str.Append(" AND person_pkid = @personId");

            if(this._cfg.ProviderType != ProviderType.SQLite) {
                str.Append(" AND as_actor = 1");
            }
            else {
                str.Append(" AND as_actor = 'True'");
            }

            using(DAL dal = new DAL(this._cfg)) {
                DbCommand cmd = dal.CreateCommand();
                cmd.CommandText = str.ToString();
                cmd.AddParameter("roleName", roleName);
                cmd.AddParameter("roleType", roleType.ToInt32());
                cmd.AddParameter("movieId", movieId);
                cmd.AddParameter("personId", personId);

                dal.ExecuteNonQuery(cmd);
            }
        }
开发者ID:vandango,项目名称:MovieMatic,代码行数:33,代码来源:DataHandler.cs


注:本文中的DAL.ExecuteNonQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。