Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:17:32+00:00 2026-05-23T14:17:32+00:00

I’ve had a look at the other issues people have reported but none of

  • 0

I’ve had a look at the other issues people have reported but none of these solve the problems I’m having. I’ve been using this walkthrough from MS to manipulate an Access DB using an ASP.net application. Unfortunately the button to add a row has worked once and no longer does anything on either my local webserver or the inbuilt .NET one. I can’t work out what the issue is and I’ve been banging my head against the desk since yesterday.

Here’s my code;

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="editTest._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:DataGrid ID="datagrid" runat="server" AutoGenerateColumns="False" 
        oncancelcommand="datagrid_CancelCommand" oneditcommand="datagrid_EditCommand" 
        onupdatecommand="datagrid_UpdateCommand">
        <Columns>
            <asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update">
            </asp:EditCommandColumn>
            <asp:BoundColumn DataField="firstName" HeaderText="First Name">
            </asp:BoundColumn>
            <asp:BoundColumn DataField="lastName" HeaderText="Surname"></asp:BoundColumn>
            <asp:BoundColumn DataField="sex" HeaderText="Gender"></asp:BoundColumn>
            <asp:BoundColumn DataField="phoneNo" HeaderText="Telephone"></asp:BoundColumn>
        </Columns>
    </asp:DataGrid>
    <div>

        <asp:Button ID="Button1" runat="server" Text="Button" />

    </div>
    </form>
</body>
</html>

and the C# end;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

namespace editTest
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) ReadRecords();
        }

        private void ReadRecords()
        {
            OleDbConnection cnt = null;
            OleDbDataReader rdr = null;

            try
            {
                cnt = new OleDbConnection(
                    "Provider=Microsoft.Jet.OLEDB.4.0; " +
                    "Data Source=" + Server.MapPath("test/accessTest.mdb"));
                cnt.Open();

                OleDbCommand cmd = new OleDbCommand("Select * FROM editTest", cnt);
                rdr = cmd.ExecuteReader();

                datagrid.DataSource = rdr;
                datagrid.DataBind();
            }

            catch (Exception e)
            {
                Response.Write(e.Message);
                Response.End();
            }

            finally
            {
                if (rdr != null) rdr.Close();
                if (cnt != null) cnt.Close();
            }
        }

        private void ExecuteNonQuery(string sql)
        {
            OleDbConnection cnt = null;
            try
            {
                cnt = new OleDbConnection(
                    "Provider=Microsoft.Jet.OLEDB.4.0; " +
                    "Data Source=" + Server.MapPath("test/accessTest.mdb"));
                cnt.Open();

                OleDbCommand cmd =
                    new OleDbCommand(sql, cnt);
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Response.Write(e.Message);
                Response.End();
            }
            finally
            {
                if (cnt != null) cnt.Close();
            }
        }

        protected void datagrid_CancelCommand(object source, DataGridCommandEventArgs e)
        {
            datagrid.EditItemIndex = -1;
            ReadRecords();
        }

        protected void datagrid_EditCommand(object source, DataGridCommandEventArgs e)
        {
            datagrid.EditItemIndex = e.Item.ItemIndex;
            ReadRecords();
        }

        protected void datagrid_UpdateCommand(object source, DataGridCommandEventArgs e)
        {
            int ID = (int)datagrid.DataKeys[(int)e.Item.ItemIndex];

            string firstName = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
            string lastName = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
            string sex = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
            string phoneNo = ((TextBox)e.Item.Cells[4].Controls[0]).Text;

            string sql =
                "UPDATE editTest SET firstName=\"" + firstName +
                "\", lastName=\"" + lastName + "\", sex=\"" + sex +
                "\", phoneNo=\"" + phoneNo + "\"" +
                " WHERE ID=" + ID;
            ExecuteNonQuery(sql);

            datagrid.EditItemIndex = -1;
            ReadRecords();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            string sql = "INSERT INTO editTest (firstName, lastName, sex, phoneNo)"
                        + " VALUES (\"new\", \"new\", \"new\", \"new\")";
            ExecuteNonQuery(sql);
            ReadRecords();
        }
    }
}

Thanks for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:17:33+00:00Added an answer on May 23, 2026 at 2:17 pm

    You missed the event on the aspx:

     <asp:Button ID="Button1" runat="server" Text="Button" OnClick='Button1_Click' />
    

    and make Button1_Click public or protected.

    Or, you can set it in the code-behind:

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) ReadRecords();
    
            Button1.Click += Button1_Click;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.