vb.net datagridview删除行数以后更新的问题!

ImportsSystem.IOImportsSystem.DataImportsSystem.Data.OleDbModuleModule1PubliccnAsNewO... Imports System.IO
Imports System.Data
Imports System.Data.OleDb

Module Module1
Public cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\aldidar.accdb")
Public DataModdif As String
Public Function DataStr(ByVal str As String) As Boolean
Dim cmdinsert As New OleDbCommand
cmdinsert.Connection = cn
cmdinsert.CommandText = str
If cn.State = ConnectionState.Closed Then cn.Open()
DataModdif = cmdinsert.ExecuteNonQuery()
cn.Close()
Return False
End Function
Public Function filDgv(ByVal str1 As String, ByVal dgv As DataGridView) As Boolean
Dim dt As New DataTable
Try
Dim da As New OleDbDataAdapter(str1, cn)
da.Fill(dt)
dgv.DataSource = dt
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function

End Module
我是基于这个模块代码控制的.现在问题是 能不能写个基于这个代码的一个更新函数!
展开
 我来答
captain2005
2015-01-20 · TA获得超过1059个赞
知道小有建树答主
回答量:2041
采纳率:40%
帮助的人:562万
展开全部
Public Class datafrm
Dim conn As SQLite.SQLiteConnection
Dim cmd As SQLite.SQLiteCommand
Dim ap As SQLite.SQLiteDataAdapter
Dim mytable As New DataTable
Private Sub datafrm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
conn = New SQLite.SQLiteConnection("data source=InfoCenter.db")
cmd = New SQLite.SQLiteCommand("select * from leader", conn)
ap = New SQLite.SQLiteDataAdapter(cmd)
conn.Open()
ap.Fill(mytable)
DataGridView1.DataSource = mytable
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DataGridView1.ReadOnly = True
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sd As New SQLite.SQLiteCommandBuilder(ap)
sd.GetUpdateCommand()
sd.GetDeleteCommand()
sd.GetInsertCommand()
ap.Update(mytable)
End Sub

Private Sub delmenu_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles delmenu.Click
DataGridView1.Rows.Remove(DataGridView1.SelectedRows.Item(0))
End Sub

Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
DataGridView1.ReadOnly = False
End Sub
End Class
你橡神毁看看有没有启示,梁备我用的瞎拍是sqlite数据库
追问
嗯嗯 我试试 谢谢哈 可以的话就你了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式