Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
when i run this progarm, after entering values and while clicking save button, i am getting the following error

An OLE DB Provider was not specified in the ConnectionString.  An example would be, Provider=SQLOLEDB;

Can someone please help me to resolve it...the code is given below..

C#
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;

namespace UItoExcelDuplicate
{
    public partial class _Default : System.Web.UI.Page
    {
        private DataTable _dt;
        public DataTable dt
        {
            get
            {
                return _dt;
            }
            set
            {
                _dt = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("CodeID", typeof(string));
                dt.Columns.Add("Content", typeof(string));
                dt.Columns.Add("Mapping Code", typeof(string));
                Session["dt"] = dt;
            }
            _dt = (DataTable) Session ["dt"];
        }
        private void BindGrid()
        {
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string con = "Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/323493/Desktop/test.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES'";
            OleDbConnection obj = new OleDbConnection(con);
            obj.Open();
            OleDbCommand cmd = new OleDbCommand("Insert into [Sheet1$]values('" + txtCodeID.Text + "','" + txtContent.Text + "','" + txtMappingCode.Text + "')", obj);
            cmd.ExecuteNonQuery();
            //MessageBox.Show("Inserted");
            obj.Close();
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)Session["dt"];
            DataRow dr = dt.NewRow();
            dr["CodeID"] = txtCodeID.Text;
            dr["Content"] = txtContent.Text;
            dr["Mapping Code"] = txtMappingCode.Text;

            dt.Rows.Add(dr);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            BindGrid();
            txtCodeID.Text = txtContent.Text = txtMappingCode.Text = string.Empty;
        }

    }
    
}


Please help me..

thanks in advance.. :)
Posted
Updated 13-Sep-12 23:42pm
v2
Comments
Sangramsingh Pawar 14-Sep-12 6:49am    
hey error itself gives solution you missing to add provider
string con = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/323493/Desktop/test.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES'";

The message is quite clear, your connection string is not valid. Go and check it at www.connectionstrings.com.
 
Share this answer
 
Seems like some of bits of connection string is missing. Have a look on ADO Connection Strings[^]
 
Share this answer
 
VB
dim Filepath= "E:\Live.xls"

Dim cn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Filepath & ";Extended Properties=""Excel 8.0;"""

Happy Coding!
:)
 
Share this answer
 
hiii,
read this article will help you

http://www.connectionstrings.com/excel-2007[^]

or

change this line

string con = "Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/323493/Desktop/test.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES'";

to

string con ="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/323493/Desktop/test.xlsx;Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
 
Share this answer
 
v2
Hi all.. Thanks for the reply..

Everything is working fine..

But I am getting a run time error as
"Missing semicolon (;) at end of SQL statement." in the line
C#
cmd.ExecuteNonQuery();


Can you please help me to identify what it is.. Since I am a beginner, Ineed some help..

Thanks a lot.
Anusha :)
 
Share this answer
 
Hi,
If i add SQLOLEDB, I am getting an error as Invalid connection string.. and i have a doubt,
Should we change the connection string in the web config?
 
Share this answer
 
v2
Comments
prashant patil 4987 17-Sep-12 0:32am    
hey try this:
string con = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/323493/Desktop/test.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES'";
try using

this connection string or make the connection method separately..and call on save button

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\serverName\shareName\folder\myDatabase.mdb;User Id=admin;Password=;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900