如何将gridview数据保存到数据库表?
问题描述:
单击一个按钮,我需要将gridview数据保存到数据库表中.在按钮上单击,我确实是这样
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);
cont.Open();
cmd1.ExecuteNonQuery();
cont.Close();
}
但是错误显示为"Microsoft Jet数据库引擎无法打开文件"..该文件已经由另一个用户独占打开,或者您需要获得查看其数据的权限."
可能是什么原因????
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 ????
答
您可能想要这样:
You probably want this :
"provider=Microsoft.Jet.OLEDB.4.0; Data Source=\"" +path+"\";Extended Properties=Excel 8.0;"
亲爱的朋友,
由于我的想法可能是您的MsExcel版本与您输入的代码不同,因此请检查MsExcel的版本.
问候,
Anilkumar.D
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