TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Yogesh Vedpathak
674
1.4k
192k
I want to save form data in excel sheet (csv) using asp.net
Jan 27 2017 1:40 AM
web.config file ...i not getting how to write web.config for excel sheet ....
<connectionStrings>
<add name="ConStr" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|InsertDataExcel.xlsx;Extended Properties=Excel 12.0"/>
</connectionStrings>
my code is here ...aspx file
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;
using System.Data;
namespace Test
{
public partial class FormToExcel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string ConStr = "";
string path = Server.MapPath("InsertDataExcel.xlsx");
ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;ReadOnly=False;HDR=Yes;\"";
string query = "INSERT INTO [InsertDataExcel.xlsx] ([FirstName], [LastName], [Address], [City], [State],[zip],[IsActive] ) VALUES('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + DropDownList1.SelectedValue + "','" + TextBox6.Text + "','" + CheckBoxList1.SelectedValue + "')";
OleDbConnection conn = new OleDbConnection(ConStr);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.Parameters.AddWithValue("@FirstName", TextBox1.Text);
cmd.Parameters.AddWithValue("@LastName", TextBox2.Text);
cmd.Parameters.AddWithValue("@LastName", TextBox3.Text);
cmd.Parameters.AddWithValue("@City", TextBox4.Text);
cmd.Parameters.AddWithValue("@State", DropDownList1.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Zip", TextBox6.Text);
cmd.Parameters.AddWithValue("@FirstName", TextBox1.Text);
cmd.Parameters.AddWithValue("@IsActive", CheckBoxList1.SelectedItem.Text);
int result = cmd.ExecuteNonQuery();
if (result > 0)
{
Response.Write("<script>alert('Sucessfully Data Inserted Into Excel')</script>");
}
else
{
Response.Write("<script>alert('Sorry!\n Insertion Failed')</script>");
}
conn.Close();
}
}
}
Reply
Answers (
1
)
How to get the value from div and it has a dt, dl tags..
jquery dialog button background color and close icon