Click here to Skip to main content
15,068,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On a button click I need to save the gridview data to database table. on the button click , I did like this
foreach (GridViewRow gvr in GridView1.Rows)
            OleDbConnection cont = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source=path;Extended Properties=Excel 8.0;");
            OleDbCommand cmd1 = new OleDbCommand("insert into [loadtogrid] (name,dept) values ('" + gvr.Cells[0].Text + "','" + gvr.Cells[2].Text + "')", cont);

But an error is shown as " The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data."

What might be the reason ????
Updated 26-Oct-11 19:53pm

You probably want this :
"provider=Microsoft.Jet.OLEDB.4.0; Data Source=\"" +path+"\";Extended Properties=Excel 8.0;"
lll1234 27-Oct-11 1:57am
Again I set the path and now the error is """Cannot update. Database or object is read-only."""
Mehdi Gholam 27-Oct-11 2:05am
Try closing all programs that have the file open first.
lll1234 27-Oct-11 3:03am
I tried but still showing error
Dear Friend,

As my Thinking May Be Your MsExcel Version is Different what you Put in your Code.So please check the Version of MsExcel.



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