本文整理汇总了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;
}
}
示例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;
}
}