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


C# DAL.ExecuteQuery方法代码示例

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


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


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