如何将gridview数据保存到数据库表? [英] How to save gridview data to database table ?

查看:396
本文介绍了如何将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


这篇关于如何将gridview数据保存到数据库表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆