在Datagridview中添加,删除,更新 [英] Add, Delete, Update in Datagridview

查看:113
本文介绍了在Datagridview中添加,删除,更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我最后写了代码来手动填充1 datagridview ...
我需要一些帮助来添加删除和更新此datagridview ...

谢谢和问候...

Hi to all.

I have write the code in the end to fill manually 1 datagridview...
I need some help for add delete and update this datagridview...

Thanks and regards......

Imports System.Data.OleDb
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Con As OleDbConnection
        Dim sqlCmd As OleDbCommand = New OleDbCommand("select * from Movement_roller_H")
        Dim myData As OleDbDataReader
        Con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source =C:\Users\Louisa\Desktop\Roller.mdb")
        Con.Open()
        sqlCmd.Connection = Con
        myData = sqlCmd.ExecuteReader

        Do While myData.Read
            Dim dgRow As New DataGridViewRow()
            dgRow.CreateCells(DataGridView1)
            dgRow.Cells(0).Value = myData.GetInt32(0)
            dgRow.Cells(1).Value = myData.GetDateTime(1).ToString("d")
            dgRow.Cells(2).Value = myData.GetString(2)
            Dim strValue3 As String = IIf(myData.IsDBNull(3), "", myData.GetValue(3))
            dgRow.Cells(3).Value = strValue3
            dgRow.Cells(4).Value = myData.GetDateTime(4).ToString("d")
            DataGridView1.Rows.Add(dgRow)
        Loop
    End Sub
End Class

推荐答案

[
This[^] may help you.

It has the example with the source code. Hope it would be helpful to you for understanding the operations related to the grid. Additionally it includes paging also.


在您编写的按钮事件上:
这是要删除的选定行!


datagridview1.rows.remove(datagridview1.curentrow)



使用表适配器管理器以简单的方式与数据库进行操作!您可以轻松创建查询
删除
更新
插入INTO
标量查询!
on button event you write:
this is for selected row to remove!


datagridview1.rows.remove(datagridview1.curentrow)



to manipulate in easy way with database is using Table adapter manager! you can easy create querys
Delete
Update
Insert INTO
Scalar Queries!


[^ ]可以为您提供帮助.
This[^] could help you.


这篇关于在Datagridview中添加,删除,更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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