Datagridview保存到数据库 [英] Datagridview save to Database

查看:335
本文介绍了Datagridview保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!
我问,我从按钮浏览文件导入文件DBF(Database Foxpro),该数据库显示在datagridview上,现在,我需要帮助:当我单击按钮SAVE时,它将获取datagridview的所有行,然后将其保存到SQL服务器数据库.

Hello!
For me ask, I import file DBF(Database Foxpro) from button browse file and this database it show on datagridview, now, i need help me : when i click button SAVE,it will fetch all row of datagridview,then it save to SQL server Database.

推荐答案

然后您需要遍历网格视图

请遵循此算法
Then you need to loop through the grid view

please follow this algorithm
decalre rwcount as bitint
For (rwcount <> gridview.rows.count )rwcount
 {
    //  Connect DB
    // Prepare query string for insert 
       "Insert into table1 (col1,col2,col3) Values (' " + gridview.row[rwcount].column[0].value  
           + "','" +gridview.row[rwcount].column[0].value + "','"  +gridview.row[rwcount].column[0].value       +  "')" 
    // Run the above qury sting
      rwcount=rwcount+1
  }


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

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