Click here to Skip to main content
15,881,859 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
C#
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);
            cont.Open();
            cmd1.ExecuteNonQuery();
            cont.Close();
        }

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 ????
Posted
Updated 26-Oct-11 19:53pm
v2

You probably want this :
C#
"provider=Microsoft.Jet.OLEDB.4.0; Data Source=\"" +path+"\";Extended Properties=Excel 8.0;"
 
Share this answer
 
Comments
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.


Regards,

Anilkumar.D
 
Share this answer
 

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