weixin_41776001 2018-03-08 03:32 采纳率: 100%
浏览 866
已结题

数据源“AccessDataSource1”不支持删除操作。

除非指定了 DeleteCommand,否则数据源“AccessDataSource1”不支持删除操作。


<asp:GridView ID ="GridView1" runat ="server" AutoGenerateColumns ="False" 
            DataKeyNames ="购物流水号" DataSourceID ="AccessDataSource1" ShowFooter ="True"  
            CellPadding ="0" GridLines ="Horizontal"  OnRowDataBound="rowdtbound" 
            RowStyle ="center"  OnRowDeleting="GridView1_RowDeleting" OnRowCancelingEdit="GridView1_RowCancelingEdit">

       <HeaderStyle Height="20px" HorizontalAlign="Center" VerticalAlign="Middle" ForeColor="White"   BackColor="black" />
            <Columns>
                <asp:BoundField DataField="购物流水号" HeaderText="购物流水号" ReadOnly="True"  SortExpression="购物流水号" />
                <asp:BoundField DataField="用户名" HeaderText="用户名" SortExpression="用户名" />
                <asp:BoundField DataField="产品编号" HeaderText="产品编号" SortExpression="产品编号" />
                <asp:BoundField DataField="产品名称" HeaderText="产品名称" SortExpression="产品名称" />
                <asp:BoundField DataField="产品单价" HeaderText="产品单价" SortExpression="产品单价" />
                <asp:BoundField DataField="购买数量" HeaderText="购买数量" SortExpression="购买数量" />
                 <asp:CommandField HeaderText="删除" ShowDeleteButton="true" />
            </Columns>
            <RowStyle HorizontalAlign ="Center" />

          </asp:GridView>


                      protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string cname = (GridView1.DataKeys[e.RowIndex].Value).ToString();
        string OleDbStr = " delete from [用户购物表] where [购物流水号]=" + Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()) + "";
        OleDbConnection myConn = GetCon();
        OleDbCommand OleDbcom = new OleDbCommand(OleDbStr, myConn);
        myConn.Open();
        OleDbcom.ExecuteNonQuery();
        ClientScript.RegisterClientScriptBlock(this.GetType(), "info", "alert('记录已删除');", true);
        myConn.Close();
        GridViewBind();
    }
  • 写回答

3条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了