从Datagrid视图将数据插入表中 [英] Inserting data into table from Datagrid view

查看:125
本文介绍了从Datagrid视图将数据插入表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我想将插入到DataGridView中的数据上传到我的SQL Server表中需要帮助...

Hello friends,
I want to upload the data Inserted into DataGridView to my sql server table needed help...

推荐答案

您应该将datagrid绑定到数据库表(反之亦然) ,因此无论何时在数据网格中添加,更新或删除数据,该数据也会反映在数据库表中.
You should bind your datagrid to your database table (or vice versa), so whenever you add, update or delete a data in your datagrid, it will also reflect in your database table.


Private Sub inserttoDatagridview()
        con.Open()
        For Each rw As DataGridViewRow In DataGridView1.Rows
            cmd = New SqlCommand("insert into tblEmp (empid,empname,empdesg,dob) values (" & rw.Cells(0).Value & ",'" & rw.Cells(1).Value & "','" & rw.Cells(2).Value & "','" & CDate(rw.Cells(3).Value.ToString()) & "') ", con)
            cmd.ExecuteNonQuery()
        Next
        con.Close()
    End Sub


这篇关于从Datagrid视图将数据插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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