using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String path = Server.MapPath("App_Data\\dnis2010.mdb");
        String sqlQuery = "INSERT INTO tableRegister (staffName,staffId,department,section,extension) VALUES (?,?,?,?,?)";

        OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + path);
        OleDbCommand aCommand = new OleDbCommand(sqlQuery, aConnection);

        aCommand.Parameters.AddWithValue("staffName", TextBox1.Text);
        aCommand.Parameters.AddWithValue("staffId", TextBox2.Text);
        aCommand.Parameters.AddWithValue("department", TextBox3.Text);
        aCommand.Parameters.AddWithValue("section", TextBox4.Text);
        aCommand.Parameters.AddWithValue("extension", TextBox5.Text);

        try
        {
            aConnection.Open();
            OleDbDataReader aReader = aCommand.ExecuteReader();
            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Successfully Insert Into Database!');</script>");

            aReader.Close();
            aConnection.Close();

        }
        catch (Exception)
        {
            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Failed to Insert Into Database!');</script>");
        }
    }
}

i don't know why it cannot function well..my friend use the same code but can function well..anyone help me..

What, if any, errors are you getting back when you attempt to run the code? This would definitely help pinpoint the cause of the problem.

Alternately, what results are you getting and what results are you expecting?

And didn't I just reply to another question about how to take a radiobutton variable and put it into an Access Database? Seems like you're everywhere I turn tonight... stop following me!! ((sorry, it's late, really bad sense of humor mode activated))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.