Dim garcucon As New OleDb.OleDbConnection
Dim concmd As New OleDb.OleDbCommand
Dim da As OleDb.OleDbDataAdapter
Dim dv As DataView
Dim ds As DataSet
Datapath = "Provider=SQLOLEDB;Data Source=XX.XX.XX.XX;Initial Catalog="默认表"; user id=user1; password=password1;"
'查询按钮
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
garcucon.ConnectionString = Datapath
garcucon.Open()
concmd.Connection = garcucon
'查询结果输出
concmd.CommandText = "select * from add2 where 组别='GA'"
'MsgBox(concmd.CommandText)
da = New OleDb.OleDbDataAdapter()
da.SelectCommand = concmd
ds = New DataSet()
da.Fill(ds, "add2")
dv = New DataView(ds.Tables("add2"))
garcucon.Close()
Label1.Visible = True
Label1.Text = "满足条件的记录数有:" + dv.Count.ToString() + "条."
dv.Sort = "序列号 Asc"
DataGridView1.Visible = True
DataGridView1.DataSource = dv
Catch ex As Exception
End Try
End Sub
'在datagirdview1中修改 相关记录之后 button2 为更新数据库按钮,报错了..........
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
da.SelectCommand = concmd
DataGridView1.Update()
da.Update(ds, "add2")
ds.AcceptChanges()
End Sub
6 个解决方案
#1
#2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim oleBuilder As New OleDbCommandBuilder(da)
da.Update(ds, "add2")
end sub
Dim oleBuilder As New OleDbCommandBuilder(da)
da.Update(ds, "add2")
end sub
#3
Dim dbBlder = New OleDb.OleDbCommandBuilder(da)
Try
da.Update(ds.Tables("add2"))
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
Try
da.Update(ds.Tables("add2"))
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
#4
大师些,虽然不报错了…… 但是 不更新数据库啊……
================
Dim da As OleDb.OleDbDataAdapter
Dim ds As DataSet
da = New OleDb.OleDbDataAdapter()
concmd.CommandText = "select * from add2 where Number='119' "
ds = New DataSet()
da.SelectCommand = concmd
da.Fill(ds, "add2")
Dim dbBlder = New OleDb.OleDbCommandBuilder(da)
Try
DataGridView1.Update()
da.Update(ds, “add2”)
ds.AcceptChanges()
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
================
Dim da As OleDb.OleDbDataAdapter
Dim ds As DataSet
da = New OleDb.OleDbDataAdapter()
concmd.CommandText = "select * from add2 where Number='119' "
ds = New DataSet()
da.SelectCommand = concmd
da.Fill(ds, "add2")
Dim dbBlder = New OleDb.OleDbCommandBuilder(da)
Try
DataGridView1.Update()
da.Update(ds, “add2”)
ds.AcceptChanges()
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
#5
ds.Tables("add2").Rows(0)(1) = "modtest"
Try
DataGridView1.Update()
da.Update(ds, “add2”)
ds.AcceptChanges()
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
手动更新后成功。。。。。z
注释掉
ds.Tables("add2").Rows(0)(1) = "modtest"
这句又不能更新……
Try
DataGridView1.Update()
da.Update(ds, “add2”)
ds.AcceptChanges()
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
手动更新后成功。。。。。z
注释掉
ds.Tables("add2").Rows(0)(1) = "modtest"
这句又不能更新……
#6
我明白了 ,我要如何在一个 Button1_Click 里面输出的 datagidview1 传递给 Button5_Click 来修改……
#1
#2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim oleBuilder As New OleDbCommandBuilder(da)
da.Update(ds, "add2")
end sub
Dim oleBuilder As New OleDbCommandBuilder(da)
da.Update(ds, "add2")
end sub
#3
Dim dbBlder = New OleDb.OleDbCommandBuilder(da)
Try
da.Update(ds.Tables("add2"))
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
Try
da.Update(ds.Tables("add2"))
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
#4
大师些,虽然不报错了…… 但是 不更新数据库啊……
================
Dim da As OleDb.OleDbDataAdapter
Dim ds As DataSet
da = New OleDb.OleDbDataAdapter()
concmd.CommandText = "select * from add2 where Number='119' "
ds = New DataSet()
da.SelectCommand = concmd
da.Fill(ds, "add2")
Dim dbBlder = New OleDb.OleDbCommandBuilder(da)
Try
DataGridView1.Update()
da.Update(ds, “add2”)
ds.AcceptChanges()
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
================
Dim da As OleDb.OleDbDataAdapter
Dim ds As DataSet
da = New OleDb.OleDbDataAdapter()
concmd.CommandText = "select * from add2 where Number='119' "
ds = New DataSet()
da.SelectCommand = concmd
da.Fill(ds, "add2")
Dim dbBlder = New OleDb.OleDbCommandBuilder(da)
Try
DataGridView1.Update()
da.Update(ds, “add2”)
ds.AcceptChanges()
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
#5
ds.Tables("add2").Rows(0)(1) = "modtest"
Try
DataGridView1.Update()
da.Update(ds, “add2”)
ds.AcceptChanges()
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
手动更新后成功。。。。。z
注释掉
ds.Tables("add2").Rows(0)(1) = "modtest"
这句又不能更新……
Try
DataGridView1.Update()
da.Update(ds, “add2”)
ds.AcceptChanges()
MsgBox("数据库更新结束")
Catch
MsgBox("数据库更新失败")
End Try
手动更新后成功。。。。。z
注释掉
ds.Tables("add2").Rows(0)(1) = "modtest"
这句又不能更新……
#6
我明白了 ,我要如何在一个 Button1_Click 里面输出的 datagidview1 传递给 Button5_Click 来修改……