//"To run this code errorfree please change/set component name what you have given at design time."
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Data.OleDb;
- public partial class addtoexcel : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- public void clearall()
- {
- txtnm.Text = "";
- txtadd.Text = "";
- txtcity.Text = "";
- txtphone.Text = "";
- txtemail.Text = "";
- }
- protected void btnsubmit_Click(object sender, EventArgs e)
- {
-
-
-
-
- string constr = "Provider=Microsoft.ACE.OLEDB.12.0;; Data Source = C:\\Users\\Administrator\\Desktop\ \Acces sdata.accdb; Persist Security Info=False;";
-
-
-
- string query = "Insert into youraccesstablename (Name, Address, City, Phone, EmailID) VALUES ('" + tx tnm.Text + "','" + txtadd.Text + "','" + txtcity.Text + "','" + txtphone.Text + "','" + txtemail.Text + "')";
- OleDbConnection con = new OleDbConnection(constr);
- if (con.State == ConnectionState.Closed)
- {
- con.Open();
- }
- OleDbCommand cmd = new OleDbCommand(query,con);
- int result = cmd.ExecuteNonQuery();
- if (result > 0)
- {
- Response.Write("<script>alert('Data Inserted Successfully.')</script>");
- }
- else
- {
- Response.Write("<script>alert('Daata not Inserted successfully.')</script>");
- }
- con.Close();
- clearall();
- }
- }