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..