default.aspx.cs

来自「visual stdio 2005」· CS 代码 · 共 91 行

CS
91
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
 




    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        Label BName = (Label)e.Item.FindControl("Label1");
        string BBName = BName.Text.ToString();

        Label BKind=(Label )e.Item .FindControl ("Label2");
        string BBKind = BKind.Text.ToString();

        Label BAuthor= (Label)e.Item.FindControl("Label4");
        string BBAuthor = BAuthor.Text.ToString();

        Label BChuban = (Label)e.Item.FindControl("Label3");
        string BBChuban = BChuban.Text.ToString();

        Label BPrice = (Label)e.Item.FindControl("Label5");
        string BBPrice = BPrice.Text.ToString();
       //Response.Write(BBPrice );

        string StrCoon = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath("BDB/BookStore.mdb");
        OleDbConnection cnA = new OleDbConnection();
        cnA.ConnectionString = StrCoon;
        cnA.Open();

        string sqlinsert = " INSERT INTO [BookCar] ([BName], [BKind],[BAuthor],[BChuban],[BPrice1],[BPrice2]) VALUES ('" + BBName + "','" + BBKind + "','" + BBAuthor + "','" + BBChuban + "','" + BBPrice + "','" + BBPrice + "')"; 
            OleDbCommand ccma = new OleDbCommand(sqlinsert, cnA);
            ccma.ExecuteNonQuery();

            cnA.Close();
            Response.Write("<script>alert('已加入到购物车!')</script>");
         
        }




    protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
    {
        Label BName = (Label)e.Item.FindControl("Label1");
        string BBName = BName.Text.ToString();

        Label BKind = (Label)e.Item.FindControl("Label2");
        string BBKind = BKind.Text.ToString();

        Label BAuthor = (Label)e.Item.FindControl("Label4");
        string BBAuthor = BAuthor.Text.ToString();

        Label BChuban = (Label)e.Item.FindControl("Label3");
        string BBChuban = BChuban.Text.ToString();

        Label BPrice = (Label)e.Item.FindControl("Label5");
        string BBPrice = BPrice.Text.ToString();
        //Response.Write(BBPrice );

        string StrCoon = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath("BDB/BookStore.mdb");
        OleDbConnection cnA = new OleDbConnection();
        cnA.ConnectionString = StrCoon;
        cnA.Open();

        string sqlinsert = " INSERT INTO [BookCar] ([BName], [BKind],[BAuthor],[BChuban],[BPrice1],[BPrice2]) VALUES ('" + BBName + "','" + BBKind + "','" + BBAuthor + "','" + BBChuban + "','" + BBPrice + "','" + BBPrice + "')";
        OleDbCommand ccma = new OleDbCommand(sqlinsert, cnA);
        ccma.ExecuteNonQuery();

        cnA.Close();
        Response.Write("<script>alert('已加入到购物车!')</script>");
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?