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
我是基于这个模块代码控制的.现在问题是 能不能写个基于这个代码的一个更新函数! 展开
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
我是基于这个模块代码控制的.现在问题是 能不能写个基于这个代码的一个更新函数! 展开
1个回答
展开全部
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数据库
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数据库
追问
嗯嗯 我试试 谢谢哈 可以的话就你了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询